diff --git a/doc/example/customization.cpp b/doc/example/customization.cpp index 30f69c3..78283a3 100644 --- a/doc/example/customization.cpp +++ b/doc/example/customization.cpp @@ -86,8 +86,8 @@ struct near_constraint template< typename Actual > bool operator()( Actual actual ) const { - return std::abs( actual - boost::unwrap_ref( expected_ ) ) - < boost::unwrap_ref( threshold_ ); + return std::abs( actual - unwrap_ref( expected_ ) ) + < unwrap_ref( threshold_ ); } friend std::ostream& operator<<( std::ostream& s, const near_constraint& c ) @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one ) mock_view v; calculator c( v ); int expected, threshold; - MOCK_EXPECT( v.display ).with( near( boost::cref( expected ), boost::cref( threshold ) ) ); + MOCK_EXPECT( v.display ).with( near( std::cref( expected ), std::cref( threshold ) ) ); expected = 42; threshold = 1; c.add( 41, 1 ); diff --git a/doc/example/patterns_retrieve_cref.cpp b/doc/example/patterns_retrieve_cref.cpp index 8be3e9a..0b5aace 100644 --- a/doc/example/patterns_retrieve_cref.cpp +++ b/doc/example/patterns_retrieve_cref.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value ) my_class c( mock ); int value; MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail - MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one + MOCK_EXPECT( mock.method ).once().with( std::cref( value ) ); // on second call compare the previously retrieved value with the newly received one c.process(); } //] diff --git a/doc/example/reference.cpp b/doc/example/reference.cpp index d599a59..d6aa41e 100644 --- a/doc/example/reference.cpp +++ b/doc/example/reference.cpp @@ -740,7 +740,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions_with_references ) { mock_class c; int i = 0; - MOCK_EXPECT( c.method ).returns( boost::ref( i ) ); // wrap i to store a reference + MOCK_EXPECT( c.method ).returns( std::ref( i ) ); // wrap i to store a reference c.method() = 42; // really change i and not just the stored copy BOOST_CHECK_EQUAL( 42, i ); // indeed } diff --git a/include/turtle/constraint.hpp b/include/turtle/constraint.hpp index dd30eab..b739239 100644 --- a/include/turtle/constraint.hpp +++ b/include/turtle/constraint.hpp @@ -11,7 +11,7 @@ #include "config.hpp" #include "log.hpp" -#include +#include "detail/unwrap_reference.hpp" #include #include #include @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace mock @@ -148,7 +149,7 @@ namespace detail expected##n( std::forward< T##n >(e##n) ) #define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \ - boost::unwrap_ref( expected##n ) + mock::detail::unwrap_ref( expected##n ) #define MOCK_CONSTRAINT_FORMAT(z, n, d) \ BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n ) @@ -160,7 +161,7 @@ namespace detail std::decay_t< const T##n > #define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \ - const typename boost::unwrap_reference< Expected_##n >::type& \ + const mock::detail::unwrap_reference_t< Expected_##n >& \ BOOST_PP_ARRAY_ELEM(n, Args) #define MOCK_CONSTRAINT_ARG(z, n, Args) \ diff --git a/include/turtle/constraints.hpp b/include/turtle/constraints.hpp index d37e433..97f72fc 100644 --- a/include/turtle/constraints.hpp +++ b/include/turtle/constraints.hpp @@ -12,7 +12,7 @@ #include "config.hpp" #include "constraint.hpp" #include "detail/move_helper.hpp" -#include +#include "detail/unwrap_reference.hpp" #include #include #if BOOST_VERSION >= 107000 @@ -20,6 +20,7 @@ #else #include #endif +#include #include #include @@ -131,24 +132,22 @@ namespace detail std::enable_if_t< has_equal_to< Actual, - typename - boost::unwrap_reference< Expected >::type + unwrap_reference_t< Expected > >::value >* = 0 ) const { - return actual == boost::unwrap_ref( expected_ ); + return actual == unwrap_ref( expected_ ); } template< typename Actual > bool operator()( const Actual& actual, std::enable_if_t< !has_equal_to< Actual, - typename - boost::unwrap_reference< Expected >::type + unwrap_reference_t< Expected > >::value >* = 0 ) const { - return actual && *actual == boost::unwrap_ref( expected_ ); + return actual && *actual == unwrap_ref( expected_ ); } friend std::ostream& operator<<( std::ostream& s, const equal& e ) { @@ -161,7 +160,7 @@ namespace detail struct same { explicit same( const Expected& expected ) - : expected_( std::addressof( boost::unwrap_ref( expected ) ) ) + : expected_( std::addressof( unwrap_ref( expected ) ) ) {} template< typename Actual > bool operator()( const Actual& actual ) const @@ -172,23 +171,21 @@ namespace detail { return os << "same( " << mock::format( *s.expected_ ) << " )"; } - const typename - boost::unwrap_reference< Expected >::type* expected_; + const unwrap_reference_t< Expected >* expected_; }; template< typename Expected > struct retrieve { explicit retrieve( Expected& expected ) - : expected_( std::addressof( boost::unwrap_ref( expected ) ) ) + : expected_( std::addressof( unwrap_ref( expected ) ) ) {} template< typename Actual > bool operator()( const Actual& actual, std::enable_if_t< !std::is_convertible< const Actual*, - typename - boost::unwrap_reference< Expected >::type + unwrap_reference_t< Expected > >::value >* = 0 ) const { @@ -200,8 +197,7 @@ namespace detail std::enable_if_t< !std::is_convertible< const Actual*, - typename - boost::unwrap_reference< Expected >::type + unwrap_reference_t< Expected > >::value >* = 0 ) const { @@ -212,8 +208,7 @@ namespace detail bool operator()( Actual& actual, std::enable_if_t< std::is_convertible< Actual*, - typename - boost::unwrap_reference< Expected >::type + unwrap_reference_t< Expected > >::value >* = 0 ) const { @@ -224,8 +219,7 @@ namespace detail { return s << "retrieve( " << mock::format( *r.expected_ ) << " )"; } - typename - boost::unwrap_reference< Expected >::type* expected_; + unwrap_reference_t< Expected >* expected_; }; template< typename Expected > @@ -237,22 +231,21 @@ namespace detail template< typename Actual > bool operator()( Actual& actual ) const { - actual = boost::unwrap_ref( expected_ ); + actual = unwrap_ref( expected_ ); return true; } template< typename Actual > bool operator()( Actual* actual, std::enable_if_t< std::is_convertible< - typename - boost::unwrap_reference< Expected >::type, + unwrap_reference_t< Expected >, Actual >::value >* = 0 ) const { if( ! actual ) return false; - *actual = boost::unwrap_ref( expected_ ); + *actual = unwrap_ref( expected_ ); return true; } friend std::ostream& operator<<( std::ostream& s, const assign& a ) @@ -270,7 +263,7 @@ namespace detail {} bool operator()( const std::string& actual ) const { - return actual.find( boost::unwrap_ref( expected_ ) ) + return actual.find( unwrap_ref( expected_ ) ) != std::string::npos; } friend std::ostream& operator<<( std::ostream& s, const contain& n ) diff --git a/include/turtle/detail/action.hpp b/include/turtle/detail/action.hpp index a959c31..155e5cb 100644 --- a/include/turtle/detail/action.hpp +++ b/include/turtle/detail/action.hpp @@ -11,7 +11,6 @@ #include "../config.hpp" #include -#include #include #include #include @@ -60,9 +59,9 @@ namespace detail a_ = a; } template< typename Y > - void set( const boost::reference_wrapper< Y >& r ) + void set( const std::reference_wrapper< Y >& r ) { - a_ = boost::bind( &do_ref< Y >, r.get_pointer() ); + a_ = boost::bind( &do_ref< Y >, &r.get() ); } private: @@ -88,10 +87,10 @@ namespace detail template< typename Value > void returns( const Value& v ) { - this->set( boost::ref( store( v ) ) ); + this->set( std::ref( store( v ) ) ); } template< typename Y > - void returns( const boost::reference_wrapper< Y >& r ) + void returns( const std::reference_wrapper< Y >& r ) { this->set( r ); } @@ -102,7 +101,7 @@ namespace detail this->set( boost::bind( &move< std::remove_reference_t< Value > >, - boost::ref( store( std::move( v ) ) ) ) ); + std::ref( store( std::move( v ) ) ) ) ); } private: @@ -183,23 +182,23 @@ namespace detail : v_( rhs.v_.release() ) { if( v_.get() ) - returns( boost::ref( v_ ) ); + returns( std::ref( v_ ) ); } template< typename Y > void returns( Y* r ) { v_.reset( r ); - this->set( boost::ref( v_ ) ); + this->set( std::ref( v_ ) ); } template< typename Y > void returns( std::auto_ptr< Y > r ) { v_ = r; - this->set( boost::ref( v_ ) ); + this->set( std::ref( v_ ) ); } template< typename Y > - void returns( const boost::reference_wrapper< Y >& r ) + void returns( const std::reference_wrapper< Y >& r ) { this->set( r ); } diff --git a/include/turtle/detail/function.hpp b/include/turtle/detail/function.hpp index e723a42..fed3802 100644 --- a/include/turtle/detail/function.hpp +++ b/include/turtle/detail/function.hpp @@ -76,7 +76,7 @@ namespace detail e_->returns( r ); } template< typename Y > - void returns( const boost::reference_wrapper< Y >& r ) + void returns( const std::reference_wrapper< Y >& r ) { e_->returns( r ); } diff --git a/include/turtle/detail/unwrap_reference.hpp b/include/turtle/detail/unwrap_reference.hpp new file mode 100644 index 0000000..376744f --- /dev/null +++ b/include/turtle/detail/unwrap_reference.hpp @@ -0,0 +1,45 @@ +// http://turtle.sourceforge.net +// +// Copyright Alexander Grund 2020 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef MOCK_UNWRAP_REFERENCE_HPP_INCLUDED +#define MOCK_UNWRAP_REFERENCE_HPP_INCLUDED + +#include +#include + +namespace mock +{ +namespace detail +{ + template + struct unwrap_reference + { + using type = T; + }; + template + struct unwrap_reference> + { + using type = T; + }; + template + struct unwrap_reference> + { + using type = T; + }; + template + using unwrap_reference_t = typename unwrap_reference::type; + + template + BOOST_FORCEINLINE unwrap_reference_t& unwrap_ref( T& t ) noexcept + { + return t; + } +} +} + +#endif // MOCK_UNWRAP_REFERENCE_HPP_INCLUDED diff --git a/include/turtle/log.hpp b/include/turtle/log.hpp index 691d5ef..b7728d0 100644 --- a/include/turtle/log.hpp +++ b/include/turtle/log.hpp @@ -123,6 +123,11 @@ namespace detail return s << mock::format( t.get() ); } template< typename T > + stream& operator<<( stream& s, const std::reference_wrapper< T >& t ) + { + return s << mock::format( t.get() ); + } + template< typename T > stream& operator<<( stream& s, const boost::shared_ptr< T >& t ) { return s << mock::format( t.get() ); diff --git a/include/turtle/matcher.hpp b/include/turtle/matcher.hpp index aed74ea..e96a970 100644 --- a/include/turtle/matcher.hpp +++ b/include/turtle/matcher.hpp @@ -14,8 +14,8 @@ #include "constraints.hpp" #include "detail/is_functor.hpp" #include "detail/move_helper.hpp" -#include #include +#include #include namespace mock @@ -30,7 +30,7 @@ namespace mock bool operator()( std::add_lvalue_reference_t< const Actual > actual ) { return mock::equal( - boost::unwrap_ref( expected_ ) ).c_( actual ); + mock::detail::unwrap_ref( expected_ ) ).c_( actual ); } friend std::ostream& operator<<( std::ostream& s, const matcher& m ) diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index 95b6d6e..d28b9a7 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -40,7 +40,7 @@ BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, mock_error_fixture BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture ) { mock::detail::function< void() > f; - std::function< void() > functor = boost::bind( boost::ref( f ) ); + std::function< void() > functor = boost::bind( std::ref( f ) ); } // invocations @@ -410,7 +410,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e { mock::detail::function< int() > f; int i = 42; - f.expect().returns( boost::ref( i ) ); + f.expect().returns( std::ref( i ) ); i = 43; BOOST_CHECK_EQUAL( 43, f() ); CHECK_CALLS( 1 ); @@ -439,7 +439,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e { mock::detail::function< int&() > f; int i = 42; - f.expect().returns( boost::ref( i ) ); + f.expect().returns( std::ref( i ) ); i = 43; BOOST_CHECK_EQUAL( 43, f() ); BOOST_CHECK_EQUAL( 12, f() = 12 ); @@ -514,7 +514,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu { mock::detail::function< std::auto_ptr< int >() > f; std::auto_ptr< int > ptr( new int( 3 ) ); - f.expect().returns( boost::ref( ptr ) ); + f.expect().returns( std::ref( ptr ) ); BOOST_CHECK_EQUAL( 3, *ptr ); BOOST_CHECK_EQUAL( 3, *f() ); BOOST_CHECK( ! ptr.get() ); @@ -638,7 +638,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er { mock::detail::function< base&() > f; derived b; - f.expect().returns( boost::ref( b ) ); + f.expect().returns( std::ref( b ) ); BOOST_CHECK_NO_THROW( f() ); CHECK_CALLS( 1 ); } @@ -651,7 +651,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er } { mock::detail::function< undefined&() > f; - f.expect().returns( boost::ref( get_undefined() ) ); + f.expect().returns( std::ref( get_undefined() ) ); f.reset(); } } @@ -917,7 +917,7 @@ BOOST_FIXTURE_TEST_CASE( function_is_thread_safe, mock_error_fixture ) mock::detail::function< int() > f; boost::thread_group group; for( int i = 0; i < 100; ++i ) - group.create_thread( boost::bind( &iterate, boost::ref( f ) ) ); + group.create_thread( boost::bind( &iterate, std::ref( f ) ) ); group.join_all(); CHECK_CALLS( 100 ); } diff --git a/test/test_constraints.cpp b/test/test_constraints.cpp index 008b117..f77d247 100644 --- a/test/test_constraints.cpp +++ b/test/test_constraints.cpp @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( equal_constraint ) BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) ); { std::string s; - BOOST_AUTO( c, mock::equal( boost::cref( s ) ) ); + BOOST_AUTO( c, mock::equal( std::cref( s ) ) ); s = "string"; BOOST_CHECK( c.c_( "string" ) ); } @@ -94,11 +94,7 @@ BOOST_AUTO_TEST_CASE( same_constraint ) int i = 0; int j = 0; BOOST_CHECK_EQUAL( i, j ); - mock::constraint< - mock::detail::same< - const boost::reference_wrapper< const int > - > - > c = mock::same( boost::cref( i ) ); + auto c = mock::same( i ); BOOST_CHECK( ! c.c_( j ) ); BOOST_CHECK( c.c_( i ) ); } @@ -137,9 +133,9 @@ BOOST_AUTO_TEST_CASE( assign_constraint ) int j = 1; mock::constraint< mock::detail::assign< - boost::reference_wrapper< const int > + std::reference_wrapper< const int > > - > c = mock::assign( boost::cref( j ) ); + > c = mock::assign( std::cref( j ) ); BOOST_CHECK( c.c_( i ) ); BOOST_CHECK_EQUAL( 1, i ); j = 3; @@ -149,11 +145,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint ) { int i = 0; int j = 1; - mock::constraint< - mock::detail::assign< - boost::reference_wrapper< const int > - > - > c = mock::assign( boost::cref( j ) ); + auto c = mock::assign( std::cref( j ) ); BOOST_CHECK( c.c_( &i ) ); BOOST_CHECK_EQUAL( 1, i ); j = 3; @@ -164,11 +156,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint ) const int* i = 0; int k = 1; int* j = &k; - mock::constraint< - mock::detail::assign< - boost::reference_wrapper< int* const > - > - > c = mock::assign( boost::cref( j ) ); + auto c = mock::assign( std::cref( j ) ); BOOST_CHECK( c.c_( i ) ); BOOST_CHECK_EQUAL( j, i ); j = 0; @@ -230,13 +218,13 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint ) { int i = 0; const int j = 1; - BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) ); + BOOST_CHECK( mock::retrieve( i ).c_( j ) ); BOOST_CHECK_EQUAL( i, j ); } { const int* i = 0; const int j = 1; - BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) ); + BOOST_CHECK( mock::retrieve( i ).c_( j ) ); BOOST_CHECK_EQUAL( i, &j ); } { @@ -332,11 +320,7 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr ) BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) ); { const char* s = 0; - mock::constraint< - mock::detail::contain< - boost::reference_wrapper< const char* const > - > - > c = mock::contain( boost::cref( s ) ); + auto c = mock::contain( std::cref( s ) ); s = "string"; BOOST_CHECK( c.c_( "this is a string" ) ); BOOST_CHECK( c.c_( std::string( "this is a string" ) ) ); @@ -356,9 +340,9 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings ) std::string s; mock::constraint< mock::detail::contain< - boost::reference_wrapper< const std::string > + std::reference_wrapper< const std::string > > - > c = mock::contain( boost::cref( s ) ); + > c = mock::contain( std::cref( s ) ); s = "string"; BOOST_CHECK( c.c_( "this is a string" ) ); BOOST_CHECK( c.c_( std::string( "this is a string" ) ) ); diff --git a/test/test_integration.cpp b/test/test_integration.cpp index e09b99b..9460fa8 100644 --- a/test/test_integration.cpp +++ b/test/test_integration.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -294,7 +293,7 @@ namespace BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture ) { - MOCK_EXPECT( manager.get_observer ).returns( boost::ref( observer ) ); + MOCK_EXPECT( manager.get_observer ).returns( std::ref( observer ) ); my_subject subject( manager ); MOCK_EXPECT( observer.notify ).once().with( 1 ); subject.increment(); @@ -395,7 +394,7 @@ BOOST_FIXTURE_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_i { boost_optional b; my_mock_observer o; - MOCK_EXPECT( b.tag ).once().returns( boost::ref( o ) ); + MOCK_EXPECT( b.tag ).once().returns( std::ref( o ) ); b.method(); CHECK_CALLS( 1 ); } @@ -460,7 +459,7 @@ BOOST_FIXTURE_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constrain { MOCK_FUNCTOR( f, void( const std::string& ) ); std::string s; - MOCK_EXPECT( f ).once().with( boost::cref( s ) ); + MOCK_EXPECT( f ).once().with( std::cref( s ) ); s = "string"; f( "string" ); CHECK_CALLS( 1 ); @@ -666,7 +665,7 @@ BOOST_FIXTURE_TEST_CASE( mock_class_is_thread_safe, mock_error_fixture ) my_mock m; boost::thread_group group; for( int i = 0; i < 100; ++i ) - group.create_thread( boost::bind( &iterate, boost::ref( m ) ) ); + group.create_thread( boost::bind( &iterate, std::ref( m ) ) ); group.join_all(); CHECK_CALLS( 100 ); } diff --git a/test/test_log.cpp b/test/test_log.cpp index 9fad50b..5b55bb6 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -517,11 +517,11 @@ BOOST_AUTO_TEST_CASE( boost_assign_map_list_of_are_serialized ) BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) ); } -BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized ) +BOOST_AUTO_TEST_CASE( std_reference_wrappers_are_serialized ) { const int i = 3; - BOOST_CHECK_EQUAL( "3", to_string( boost::cref( i ) ) ); - BOOST_CHECK_EQUAL( "\"string\"", to_string( boost::cref( "string" ) ) ); + BOOST_CHECK_EQUAL( "3", to_string( std::cref( i ) ) ); + BOOST_CHECK_EQUAL( "\"string\"", to_string( std::cref( "string" ) ) ); } namespace diff --git a/test/test_matcher.cpp b/test/test_matcher.cpp index c28648e..86197a8 100644 --- a/test/test_matcher.cpp +++ b/test/test_matcher.cpp @@ -28,8 +28,8 @@ BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared ) BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared ) { const int i = 3; - BOOST_CHECK( match( 3, boost::cref( i ) ) ); - BOOST_CHECK( ! match( 4, boost::cref( i ) ) ); + BOOST_CHECK( match( 3, std::cref( i ) ) ); + BOOST_CHECK( ! match( 4, std::cref( i ) ) ); } namespace diff --git a/test/test_mock.cpp b/test/test_mock.cpp index 516cd9b..2f0d42f 100644 --- a/test/test_mock.cpp +++ b/test/test_mock.cpp @@ -44,7 +44,7 @@ namespace BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture ) { mock_class_with_operator m; - MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) ); + MOCK_EXPECT( m.addition ).once().returns( std::ref( m ) ); m += 1; CHECK_CALLS( 1 ); }