Replace Boost.Move by std equivalents

This commit is contained in:
Alexander Grund 2020-07-05 17:29:44 +02:00
parent b86100a667
commit 9e664b52ab
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
15 changed files with 44 additions and 108 deletions

View file

@ -27,6 +27,8 @@ configure_file(version.hpp.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/vers
add_library(turtle INTERFACE) add_library(turtle INTERFACE)
add_library(turtle::turtle ALIAS turtle) add_library(turtle::turtle ALIAS turtle)
target_include_directories(turtle INTERFACE $<BUILD_INTERFACE:include;${CMAKE_CURRENT_BINARY_DIR}/include>) target_include_directories(turtle INTERFACE $<BUILD_INTERFACE:include;${CMAKE_CURRENT_BINARY_DIR}/include>)
target_compile_features(turtle INTERFACE cxx_std_14)
target_link_libraries(turtle INTERFACE Boost::boost Boost::disable_autolinking) target_link_libraries(turtle INTERFACE Boost::boost Boost::disable_autolinking)
if(NOT TURTLE_AUTO_PTR) if(NOT TURTLE_AUTO_PTR)
target_compile_definitions(turtle INTERFACE MOCK_NO_AUTO_PTR) target_compile_definitions(turtle INTERFACE MOCK_NO_AUTO_PTR)

View file

@ -64,12 +64,6 @@
# endif # endif
#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) #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
# ifndef MOCK_NO_HDR_FUNCTIONAL # ifndef MOCK_NO_HDR_FUNCTIONAL
# define MOCK_HDR_FUNCTIONAL # define MOCK_HDR_FUNCTIONAL

View file

@ -19,7 +19,6 @@
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/array.hpp> #include <boost/preprocessor/array.hpp>
#include <boost/move/move.hpp>
#include <boost/type_traits/decay.hpp> #include <boost/type_traits/decay.hpp>
namespace mock namespace mock
@ -147,7 +146,7 @@ namespace detail
const mock::constraint< detail::Name > Name; const mock::constraint< detail::Name > Name;
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \ #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) \ #define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
boost::unwrap_ref( expected##n ) boost::unwrap_ref( expected##n )
@ -166,13 +165,13 @@ namespace detail
BOOST_PP_ARRAY_ELEM(n, Args) BOOST_PP_ARRAY_ELEM(n, Args)
#define MOCK_CONSTRAINT_ARG(z, 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) \ #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) \ #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) \ #define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
namespace detail \ namespace detail \

View file

@ -190,7 +190,7 @@ namespace detail
return true; return true;
} }
template< typename Actual > template< typename Actual >
bool operator()( BOOST_RV_REF(Actual) actual, bool operator()( Actual&& actual,
typename boost::disable_if< typename boost::disable_if<
boost::is_convertible< boost::is_convertible<
const Actual*, const Actual*,
@ -199,7 +199,7 @@ namespace detail
> >
>::type* = 0 ) const >::type* = 0 ) const
{ {
*expected_ = boost::move( actual ); *expected_ = std::move( actual );
return true; return true;
} }
template< typename Actual > template< typename Actual >
@ -276,9 +276,9 @@ namespace detail
} }
template< typename T > 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 > template< typename T >

View file

@ -14,7 +14,6 @@
#include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_const.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/move/move.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
@ -105,19 +104,19 @@ namespace detail
} }
template< typename Value > template< typename Value >
void moves( BOOST_RV_REF(Value) v ) void moves( Value&& v )
{ {
this->set( this->set(
boost::bind( boost::bind(
&move< typename boost::remove_reference< Value >::type >, &move< typename boost::remove_reference< Value >::type >,
boost::ref( store( boost::move( v ) ) ) ) ); boost::ref( store( std::move( v ) ) ) ) );
} }
private: private:
template< typename Value > 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 struct value : boost::noncopyable
{ {
@ -134,8 +133,8 @@ namespace detail
>::type >::type
>::type value_type; >::type value_type;
value_imp( BOOST_RV_REF(value_type) t ) value_imp( value_type&& t )
: t_( boost::move( t ) ) : t_( std::move( t ) )
{} {}
value_imp( const value_type& t ) value_imp( const value_type& t )
: t_( t ) : t_( t )
@ -148,9 +147,9 @@ namespace detail
}; };
template< typename T > 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_; return static_cast< value_imp< T >& >( *v_ ).t_;
} }
template< typename T > template< typename T >

View file

@ -15,7 +15,7 @@
matcher< T##n, Constraint_##n > c##n##_; matcher< T##n, Constraint_##n > c##n##_;
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \ #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) \ #define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
BOOST_PP_IF(n, << ", " <<,) c##n##_ BOOST_PP_IF(n, << ", " <<,) c##n##_
@ -24,7 +24,7 @@
BOOST_PP_IF(n, << ", " <<,) "any" BOOST_PP_IF(n, << ", " <<,) "any"
#define MOCK_EXPECTATION_PARAM(z, n, Args) \ #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) \ #define MOCK_REF_ARG(z, n, d) \
typename ref_arg< T##n >::type a##n typename ref_arg< T##n >::type a##n

View file

@ -34,7 +34,6 @@
#include <boost/call_traits.hpp> #include <boost/call_traits.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/move/move.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <ostream> #include <ostream>
#include <vector> #include <vector>

View file

@ -25,7 +25,7 @@
<< lazy_expectations( this ) << lazy_expectations( this )
#define MOCK_MOVE(z, n, d) \ #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 namespace mock
{ {
@ -99,21 +99,22 @@ namespace detail
{ {
private: private:
typedef wrapper_base< R, expectation_type > base_type; typedef wrapper_base< R, expectation_type > base_type;
BOOST_MOVABLE_BUT_NOT_COPYABLE(wrapper)
public: public:
wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e ) wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e )
: base_type( e ) : base_type( e )
, lock_( m ) , lock_( m )
{} {}
wrapper( BOOST_RV_REF( wrapper ) x ) wrapper(const wrapper&) = delete;
wrapper( wrapper&& x )
: base_type( 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; static_cast< base_type& >( *this ) = x;
lock_ = boost::move( x.lock_ ); lock_ = std::move( x.lock_ );
return *this; return *this;
} }
wrapper& once() wrapper& once()
@ -200,9 +201,9 @@ namespace detail
this->e_->throws( t ); this->e_->throws( t );
} }
template< typename TT > 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_; lock lock_;

View file

@ -9,7 +9,7 @@
#include "function_impl_template.hpp" #include "function_impl_template.hpp"
#define MOCK_MOVE(z, n, d) \ #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 namespace mock
{ {

View file

@ -9,24 +9,14 @@
#ifndef MOCK_MOVE_HELPER_HPP_INCLUDED #ifndef MOCK_MOVE_HELPER_HPP_INCLUDED
#define MOCK_MOVE_HELPER_HPP_INCLUDED #define MOCK_MOVE_HELPER_HPP_INCLUDED
#include "../config.hpp"
#include <boost/type_traits/conditional.hpp> #include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_reference.hpp> #include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_rvalue_reference.hpp> #include <boost/type_traits/add_rvalue_reference.hpp>
#include <boost/type_traits/decay.hpp>
namespace mock namespace mock
{ {
namespace detail namespace detail
{ {
#ifdef MOCK_RVALUE_REFERENCES
template< typename T >
struct forward_type
{
typedef T type;
};
template< typename T > template< typename T >
struct ref_arg struct ref_arg
{ {
@ -35,43 +25,6 @@ namespace detail
T, T,
typename boost::add_rvalue_reference< T >::type >::type type; 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
} }
} }

View file

@ -11,7 +11,6 @@
#include "../config.hpp" #include "../config.hpp"
#include "singleton.hpp" #include "singleton.hpp"
#include <boost/move/move.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -38,9 +37,6 @@ namespace detail
struct lock struct lock
{ {
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
public: public:
lock( const boost::shared_ptr< mutex >& m ) lock( const boost::shared_ptr< mutex >& m )
: m_( m ) : m_( m )
@ -52,13 +48,15 @@ namespace detail
if( m_ ) if( m_ )
m_->unlock(); m_->unlock();
} }
lock( BOOST_RV_REF( lock ) x ) lock( const lock& ) = delete;
lock( lock&& x )
: m_( x.m_ ) : m_( x.m_ )
{ {
// Explicit reset to avoid unlock in destructor // Explicit reset to avoid unlock in destructor
x.m_.reset(); x.m_.reset();
} }
lock& operator=( BOOST_RV_REF( lock ) x ) lock& operator=( const lock& ) = delete;
lock& operator=( lock&& x )
{ {
m_ = x.m_; m_ = x.m_;
x.m_.reset(); x.m_.reset();
@ -86,29 +84,24 @@ namespace detail
}; };
// Dummy lock classes. // Dummy lock classes.
// Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings // 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( mutex& )
{} {}
~scoped_lock() ~scoped_lock()
{} {}
}; };
class lock : boost::noncopyable class lock
{ {
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
public: public:
lock( const boost::shared_ptr< mutex >& ) lock( const boost::shared_ptr< mutex >& )
{} {}
~lock() ~lock()
{} {}
lock( BOOST_RV_REF( lock ) ) lock(const lock&) = delete;
{} lock( lock&& ) = default;
lock& operator=( BOOST_RV_REF( lock ) ) lock& operator=( const lock& ) = delete;
{ lock& operator=( lock&& ) = default;
return *this;
}
}; };
} }
} // mock } // mock

View file

@ -71,7 +71,7 @@ namespace mock
{} {}
bool operator()( typename detail::ref_arg< Actual >::type actual ) 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<<( friend std::ostream& operator<<(
std::ostream& s, const matcher& m ) std::ostream& s, const matcher& m )
@ -95,7 +95,7 @@ namespace mock
{} {}
bool operator()( typename detail::ref_arg< Actual >::type actual ) 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<<( friend std::ostream& operator<<(
std::ostream& s, const matcher& m ) std::ostream& s, const matcher& m )

View file

@ -87,7 +87,7 @@
BOOST_PP_COMMA_IF(n) d, n >::type >( p##n ) BOOST_PP_COMMA_IF(n) d, n >::type >( p##n )
#define MOCK_FORWARD_PARAMS(n, S, tpn) \ #define MOCK_FORWARD_PARAMS(n, S, tpn) \
BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, \ 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) \ #define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
MOCK_DECL(M, n, S, c, tpn) \ MOCK_DECL(M, n, S, c, tpn) \
{ \ { \

View file

@ -575,8 +575,6 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu
#endif // MOCK_AUTO_PTR #endif // MOCK_AUTO_PTR
#ifdef MOCK_RVALUE_REFERENCES
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture )
{ {
mock::detail::function< int() > f; 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 ); CHECK_CALLS( 1 );
} }
#endif
#ifdef MOCK_SMART_PTR #ifdef MOCK_SMART_PTR
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lvalue, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lvalue, mock_error_fixture )

View file

@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint )
{ {
std::unique_ptr< int > i; std::unique_ptr< int > i;
std::unique_ptr< int > j( new int( 3 ) ); 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_REQUIRE( i );
BOOST_CHECK_EQUAL( 3, *i ); BOOST_CHECK_EQUAL( 3, *i );
BOOST_CHECK( !j ); BOOST_CHECK( !j );