diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b6828..9a91641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ configure_file(version.hpp.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/vers add_library(turtle INTERFACE) add_library(turtle::turtle ALIAS turtle) target_include_directories(turtle INTERFACE $) +target_compile_features(turtle INTERFACE cxx_std_14) + target_link_libraries(turtle INTERFACE Boost::boost Boost::disable_autolinking) if(NOT TURTLE_AUTO_PTR) target_compile_definitions(turtle INTERFACE MOCK_NO_AUTO_PTR) diff --git a/include/turtle/config.hpp b/include/turtle/config.hpp index 16b0ed5..6876926 100644 --- a/include/turtle/config.hpp +++ b/include/turtle/config.hpp @@ -64,12 +64,6 @@ # endif #endif -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_RVALUE_REFERENCES) -# ifndef MOCK_NO_RVALUE_REFERENCES -# define MOCK_RVALUE_REFERENCES -# endif -#endif - #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) # ifndef MOCK_NO_HDR_FUNCTIONAL # define MOCK_HDR_FUNCTIONAL diff --git a/include/turtle/constraint.hpp b/include/turtle/constraint.hpp index 887a22d..a8c9d4f 100644 --- a/include/turtle/constraint.hpp +++ b/include/turtle/constraint.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include namespace mock @@ -147,7 +146,7 @@ namespace detail const mock::constraint< detail::Name > Name; #define MOCK_CONSTRAINT_ASSIGN(z, n, d) \ - expected##n( boost::forward< T##n >(e##n) ) + expected##n( std::forward< T##n >(e##n) ) #define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \ boost::unwrap_ref( expected##n ) @@ -166,13 +165,13 @@ namespace detail BOOST_PP_ARRAY_ELEM(n, Args) #define MOCK_CONSTRAINT_ARG(z, n, Args) \ - BOOST_FWD_REF(T##n) BOOST_PP_ARRAY_ELEM(n, Args) + T##n&& BOOST_PP_ARRAY_ELEM(n, Args) #define MOCK_CONSTRAINT_ARGS(z, n, Args) \ - BOOST_FWD_REF(T##n) e##n + T##n&& e##n #define MOCK_CONSTRAINT_PARAM(z, n, Args) \ - boost::forward< T##n >( BOOST_PP_ARRAY_ELEM(n, Args) ) + std::forward< T##n >( BOOST_PP_ARRAY_ELEM(n, Args) ) #define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \ namespace detail \ diff --git a/include/turtle/constraints.hpp b/include/turtle/constraints.hpp index c17320f..4d4f9f1 100644 --- a/include/turtle/constraints.hpp +++ b/include/turtle/constraints.hpp @@ -190,7 +190,7 @@ namespace detail return true; } template< typename Actual > - bool operator()( BOOST_RV_REF(Actual) actual, + bool operator()( Actual&& actual, typename boost::disable_if< boost::is_convertible< const Actual*, @@ -199,7 +199,7 @@ namespace detail > >::type* = 0 ) const { - *expected_ = boost::move( actual ); + *expected_ = std::move( actual ); return true; } template< typename Actual > @@ -276,9 +276,9 @@ namespace detail } template< typename T > - constraint< detail::equal< typename detail::forward_type< T >::type > > equal( BOOST_FWD_REF(T) t ) + constraint< detail::equal< T > > equal( T&& t ) { - return detail::equal< typename detail::forward_type< T >::type >( boost::forward< T >( t ) ); + return detail::equal< T >( std::forward< T >( t ) ); } template< typename T > diff --git a/include/turtle/detail/action.hpp b/include/turtle/detail/action.hpp index a146130..47360d8 100644 --- a/include/turtle/detail/action.hpp +++ b/include/turtle/detail/action.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -105,19 +104,19 @@ namespace detail } template< typename Value > - void moves( BOOST_RV_REF(Value) v ) + void moves( Value&& v ) { this->set( boost::bind( &move< typename boost::remove_reference< Value >::type >, - boost::ref( store( boost::move( v ) ) ) ) ); + boost::ref( store( std::move( v ) ) ) ) ); } private: template< typename Value > - static BOOST_RV_REF(Value) move( Value& t ) + static Value&& move( Value& t ) { - return boost::move( t ); + return std::move( t ); } struct value : boost::noncopyable { @@ -134,8 +133,8 @@ namespace detail >::type >::type value_type; - value_imp( BOOST_RV_REF(value_type) t ) - : t_( boost::move( t ) ) + value_imp( value_type&& t ) + : t_( std::move( t ) ) {} value_imp( const value_type& t ) : t_( t ) @@ -148,9 +147,9 @@ namespace detail }; template< typename T > - T& store( BOOST_RV_REF(T) t ) + T& store( T&& t ) { - v_.reset( new value_imp< T >( boost::move( t ) ) ); + v_.reset( new value_imp< T >( std::move( t ) ) ); return static_cast< value_imp< T >& >( *v_ ).t_; } template< typename T > diff --git a/include/turtle/detail/expectation_template.hpp b/include/turtle/detail/expectation_template.hpp index 8b4cf40..39e8938 100644 --- a/include/turtle/detail/expectation_template.hpp +++ b/include/turtle/detail/expectation_template.hpp @@ -15,7 +15,7 @@ matcher< T##n, Constraint_##n > c##n##_; #define MOCK_EXPECTATION_IS_VALID(z, n, d) \ - BOOST_PP_IF(n, &&,) c##n##_( mock::detail::move_if_not_lvalue_reference< T##n >( a##n ) ) + BOOST_PP_IF(n, &&,) c##n##_( std::forward< T##n >( a##n ) ) #define MOCK_EXPECTATION_SERIALIZE(z, n, d) \ BOOST_PP_IF(n, << ", " <<,) c##n##_ @@ -24,7 +24,7 @@ BOOST_PP_IF(n, << ", " <<,) "any" #define MOCK_EXPECTATION_PARAM(z, n, Args) \ - mock::detail::move_if_not_lvalue_reference< T##n >( a##n ) + std::forward< T##n >( a##n ) #define MOCK_REF_ARG(z, n, d) \ typename ref_arg< T##n >::type a##n diff --git a/include/turtle/detail/function.hpp b/include/turtle/detail/function.hpp index a17dfec..24381da 100644 --- a/include/turtle/detail/function.hpp +++ b/include/turtle/detail/function.hpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/include/turtle/detail/function_impl_template.hpp b/include/turtle/detail/function_impl_template.hpp index 3a68971..b67c124 100644 --- a/include/turtle/detail/function_impl_template.hpp +++ b/include/turtle/detail/function_impl_template.hpp @@ -25,7 +25,7 @@ << lazy_expectations( this ) #define MOCK_MOVE(z, n, d) \ - mock::detail::move_if_not_lvalue_reference< T##n >( t##n ) + std::forward< T##n >( t##n ) namespace mock { @@ -99,21 +99,22 @@ namespace detail { private: typedef wrapper_base< R, expectation_type > base_type; - BOOST_MOVABLE_BUT_NOT_COPYABLE(wrapper) public: wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e ) : base_type( e ) , lock_( m ) {} - wrapper( BOOST_RV_REF( wrapper ) x ) + wrapper(const wrapper&) = delete; + wrapper( wrapper&& x ) : base_type( x ) - , lock_( boost::move( x.lock_) ) + , lock_( std::move( x.lock_) ) {} - wrapper& operator=( BOOST_RV_REF( wrapper ) x ) + wrapper& operator=(const wrapper&) = delete; + wrapper& operator=( wrapper&& x ) { static_cast< base_type& >( *this ) = x; - lock_ = boost::move( x.lock_ ); + lock_ = std::move( x.lock_ ); return *this; } wrapper& once() @@ -200,9 +201,9 @@ namespace detail this->e_->throws( t ); } template< typename TT > - void moves( BOOST_RV_REF(TT) t ) + void moves( TT&& t ) { - this->e_->moves( boost::move( t ) ); + this->e_->moves( std::move( t ) ); } lock lock_; diff --git a/include/turtle/detail/function_template.hpp b/include/turtle/detail/function_template.hpp index 0ebfe14..6d8a01d 100644 --- a/include/turtle/detail/function_template.hpp +++ b/include/turtle/detail/function_template.hpp @@ -9,7 +9,7 @@ #include "function_impl_template.hpp" #define MOCK_MOVE(z, n, d) \ - mock::detail::move_if_not_lvalue_reference< T##n >( t##n ) + std::forward< T##n >( t##n ) namespace mock { diff --git a/include/turtle/detail/move_helper.hpp b/include/turtle/detail/move_helper.hpp index 87f1f2d..75b173d 100644 --- a/include/turtle/detail/move_helper.hpp +++ b/include/turtle/detail/move_helper.hpp @@ -9,24 +9,14 @@ #ifndef MOCK_MOVE_HELPER_HPP_INCLUDED #define MOCK_MOVE_HELPER_HPP_INCLUDED -#include "../config.hpp" #include #include -#include -#include #include -#include namespace mock { namespace detail { -#ifdef MOCK_RVALUE_REFERENCES - template< typename T > - struct forward_type - { - typedef T type; - }; template< typename T > struct ref_arg { @@ -35,43 +25,6 @@ namespace detail T, typename boost::add_rvalue_reference< T >::type >::type type; }; - - template< typename T > - inline T&& move_if_not_lvalue_reference(typename boost::remove_reference< T >::type& t) - { - return static_cast< T&& >(t); - } - - template< typename T > - inline T&& move_if_not_lvalue_reference(typename boost::remove_reference< T >::type&& t) - { - return static_cast< T&& >(t); - } -#else - template< typename T > - struct forward_type - { - typedef typename boost::decay< const T >::type type; - }; - template< class T> - struct forward_type< boost::rv< T > > - { - typedef T type; - }; - template< typename T > - struct ref_arg - { - typedef typename boost::conditional< - boost::is_reference< T >::value, - T, - const typename boost::add_reference< T >::type >::type type; - }; - template< typename T > - inline typename boost::remove_reference< T >::type& move_if_not_lvalue_reference(typename boost::remove_reference< T >::type& t) - { - return t; - } -#endif } } diff --git a/include/turtle/detail/mutex.hpp b/include/turtle/detail/mutex.hpp index b5dcb35..3be9f02 100644 --- a/include/turtle/detail/mutex.hpp +++ b/include/turtle/detail/mutex.hpp @@ -11,7 +11,6 @@ #include "../config.hpp" #include "singleton.hpp" -#include #include #include @@ -38,9 +37,6 @@ namespace detail struct lock { - private: - BOOST_MOVABLE_BUT_NOT_COPYABLE(lock) - public: lock( const boost::shared_ptr< mutex >& m ) : m_( m ) @@ -52,13 +48,15 @@ namespace detail if( m_ ) m_->unlock(); } - lock( BOOST_RV_REF( lock ) x ) + lock( const lock& ) = delete; + lock( lock&& x ) : m_( x.m_ ) { // Explicit reset to avoid unlock in destructor x.m_.reset(); } - lock& operator=( BOOST_RV_REF( lock ) x ) + lock& operator=( const lock& ) = delete; + lock& operator=( lock&& x ) { m_ = x.m_; x.m_.reset(); @@ -86,29 +84,24 @@ namespace detail }; // Dummy lock classes. // Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings - struct scoped_lock : boost::noncopyable + struct scoped_lock { scoped_lock( mutex& ) {} ~scoped_lock() {} }; - class lock : boost::noncopyable + class lock { - private: - BOOST_MOVABLE_BUT_NOT_COPYABLE(lock) - public: lock( const boost::shared_ptr< mutex >& ) {} ~lock() {} - lock( BOOST_RV_REF( lock ) ) - {} - lock& operator=( BOOST_RV_REF( lock ) ) - { - return *this; - } + lock(const lock&) = delete; + lock( lock&& ) = default; + lock& operator=( const lock& ) = delete; + lock& operator=( lock&& ) = default; }; } } // mock diff --git a/include/turtle/matcher.hpp b/include/turtle/matcher.hpp index c6082a7..4429164 100644 --- a/include/turtle/matcher.hpp +++ b/include/turtle/matcher.hpp @@ -71,7 +71,7 @@ namespace mock {} bool operator()( typename detail::ref_arg< Actual >::type actual ) { - return c_( mock::detail::move_if_not_lvalue_reference< typename detail::ref_arg< Actual >::type >( actual ) ); + return c_( std::forward< typename detail::ref_arg< Actual >::type >( actual ) ); } friend std::ostream& operator<<( std::ostream& s, const matcher& m ) @@ -95,7 +95,7 @@ namespace mock {} bool operator()( typename detail::ref_arg< Actual >::type actual ) { - return c_( mock::detail::move_if_not_lvalue_reference< typename detail::ref_arg< Actual >::type >( actual ) ); + return c_( std::forward< typename detail::ref_arg< Actual >::type >( actual ) ); } friend std::ostream& operator<<( std::ostream& s, const matcher& m ) diff --git a/include/turtle/mock.hpp b/include/turtle/mock.hpp index f873cee..d5c5cff 100644 --- a/include/turtle/mock.hpp +++ b/include/turtle/mock.hpp @@ -87,7 +87,7 @@ BOOST_PP_COMMA_IF(n) d, n >::type >( p##n ) #define MOCK_FORWARD_PARAMS(n, S, tpn) \ BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, \ - mock::detail::move_if_not_lvalue_reference< MOCK_PARAM(S, tpn)) + std::forward< MOCK_PARAM(S, tpn)) #define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \ MOCK_DECL(M, n, S, c, tpn) \ { \ diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index 682840a..270fbe2 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -575,8 +575,6 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu #endif // MOCK_AUTO_PTR -#ifdef MOCK_RVALUE_REFERENCES - BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture ) { mock::detail::function< int() > f; @@ -603,8 +601,6 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_rvalue, mock_er CHECK_CALLS( 1 ); } -#endif - #ifdef MOCK_SMART_PTR BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lvalue, mock_error_fixture ) diff --git a/test/test_constraints.cpp b/test/test_constraints.cpp index 9e918da..26087ea 100644 --- a/test/test_constraints.cpp +++ b/test/test_constraints.cpp @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint ) { std::unique_ptr< int > i; std::unique_ptr< int > j( new int( 3 ) ); - BOOST_CHECK( mock::retrieve( i ).c_( boost::move( j ) ) ); + BOOST_CHECK( mock::retrieve( i ).c_( std::move( j ) ) ); BOOST_REQUIRE( i ); BOOST_CHECK_EQUAL( 3, *i ); BOOST_CHECK( !j );