Replace Boost.TypeTraits by std equivalents

This commit is contained in:
Alexander Grund 2020-07-05 18:10:24 +02:00
parent 9e664b52ab
commit df5b77af95
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
13 changed files with 76 additions and 113 deletions

View file

@ -46,12 +46,6 @@
# endif
#endif
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_DECLTYPE)
# ifndef MOCK_NO_DECLTYPE
# define MOCK_DECLTYPE
# endif
#endif
#if !defined(BOOST_NO_CXX11_VARIADIC_MACROS) && !defined(BOOST_NO_VARIADIC_MACROS)
# ifndef MOCK_NO_VARIADIC_MACROS
# define MOCK_VARIADIC_MACROS

View file

@ -19,7 +19,7 @@
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/array.hpp>
#include <boost/type_traits/decay.hpp>
#include <type_traits>
namespace mock
{
@ -158,7 +158,7 @@ namespace detail
Expected_##n expected##n;
#define MOCK_CONSTRAINT_TPL_TYPE(z, n, d) \
typename boost::decay< const T##n >::type
std::decay_t< const T##n >
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
const typename boost::unwrap_reference< Expected_##n >::type& \

View file

@ -15,15 +15,13 @@
#include "detail/move_helper.hpp"
#include <boost/ref.hpp>
#include <boost/version.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/common_type.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/has_equal_to.hpp>
#include <boost/type_traits/make_void.hpp>
#if BOOST_VERSION >= 107000
#include <boost/test/tools/floating_point_comparison.hpp>
#else
#include <boost/test/floating_point_comparison.hpp>
#endif
#include <type_traits>
namespace mock
{
@ -65,7 +63,7 @@ namespace detail
template< typename T1, typename T2, typename Tolerance >
bool is_close( const T1& t1, const T2& t2, const Tolerance& tolerance )
{
typedef typename boost::common_type< T1, T2 >::type common_type;
typedef std::common_type_t< T1, T2 > common_type;
return boost::math::fpc::close_at_tolerance< common_type >(
tolerance, boost::math::fpc::FPC_STRONG )( t1, t2 );
}
@ -114,6 +112,14 @@ namespace detail
namespace detail
{
template<class T, class U = T, class = void>
struct has_equal_to: std::false_type
{};
template<class T, class U>
struct has_equal_to<T, U, boost::void_t<decltype(std::declval<T>() == std::declval<U>())>>: std::true_type
{};
template< typename Expected >
struct equal
{
@ -122,25 +128,25 @@ namespace detail
{}
template< typename Actual >
bool operator()( const Actual& actual,
typename boost::enable_if<
boost::has_equal_to<
std::enable_if_t<
has_equal_to<
Actual,
typename
boost::unwrap_reference< Expected >::type
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
return actual == boost::unwrap_ref( expected_ );
}
template< typename Actual >
bool operator()( const Actual& actual,
typename boost::disable_if<
boost::has_equal_to<
std::enable_if_t<
!has_equal_to<
Actual,
typename
boost::unwrap_reference< Expected >::type
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
return actual && *actual == boost::unwrap_ref( expected_ );
}
@ -178,38 +184,38 @@ namespace detail
{}
template< typename Actual >
bool operator()( const Actual& actual,
typename boost::disable_if<
boost::is_convertible<
std::enable_if_t<
!std::is_convertible<
const Actual*,
typename
boost::unwrap_reference< Expected >::type
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
*expected_ = actual;
return true;
}
template< typename Actual >
bool operator()( Actual&& actual,
typename boost::disable_if<
boost::is_convertible<
std::enable_if_t<
!std::is_convertible<
const Actual*,
typename
boost::unwrap_reference< Expected >::type
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
*expected_ = std::move( actual );
return true;
}
template< typename Actual >
bool operator()( Actual& actual,
typename boost::enable_if<
boost::is_convertible< Actual*,
std::enable_if_t<
std::is_convertible< Actual*,
typename
boost::unwrap_reference< Expected >::type
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
*expected_ = detail::addressof( actual );
return true;
@ -236,13 +242,13 @@ namespace detail
}
template< typename Actual >
bool operator()( Actual* actual,
typename boost::enable_if<
boost::is_convertible<
std::enable_if_t<
std::is_convertible<
typename
boost::unwrap_reference< Expected >::type,
Actual
>
>::type* = 0 ) const
>::value
>* = 0 ) const
{
if( ! actual )
return false;

View file

@ -10,13 +10,12 @@
#define MOCK_ACTION_HPP_INCLUDED
#include "../config.hpp"
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <type_traits>
namespace mock
{
@ -108,7 +107,7 @@ namespace detail
{
this->set(
boost::bind(
&move< typename boost::remove_reference< Value >::type >,
&move< std::remove_reference_t< Value > >,
boost::ref( store( std::move( v ) ) ) ) );
}
@ -126,12 +125,7 @@ namespace detail
template< typename T >
struct value_imp : value
{
typedef
typename boost::remove_const<
typename boost::remove_reference<
T
>::type
>::type value_type;
typedef std::remove_const_t<std::remove_reference_t<T>> value_type;
value_imp( value_type&& t )
: t_( std::move( t ) )
@ -159,7 +153,7 @@ namespace detail
return static_cast< value_imp< T >& >( *v_ ).t_;
}
template< typename T >
typename boost::remove_reference< Result >::type& store( T* t )
std::remove_reference_t< Result >& store( T* t )
{
v_.reset( new value_imp< Result >( t ) );
return static_cast< value_imp< Result >& >( *v_ ).t_;

View file

@ -11,10 +11,11 @@
#include "../config.hpp"
#include <boost/function_types/is_callable_builtin.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/utility/declval.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/make_void.hpp>
#include <type_traits>
namespace mock
{
@ -24,33 +25,18 @@ namespace detail
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( sig )
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( result )
#ifdef MOCK_DECLTYPE
template< typename F, typename P, class = void >
struct is_callable : std::false_type
{};
template< typename F, typename P >
struct is_callable
{
typedef boost::type_traits::yes_type yes_type;
typedef boost::type_traits::no_type no_type;
template< typename T >
static yes_type check(
decltype( boost::declval< T >()( boost::declval< P >() ) )* );
template< typename T >
static no_type check( ... );
typedef boost::mpl::bool_<
sizeof( check< F >( 0 ) ) == sizeof( yes_type ) > type;
};
#endif // MOCK_DECLTYPE
struct is_callable< F, P, boost::void_t<decltype( std::declval<F>()( std::declval<P>() ) )> >: std::true_type
{};
template< typename T, typename P >
struct is_functor
: boost::mpl::or_<
boost::function_types::is_callable_builtin< T >,
#ifdef MOCK_DECLTYPE
is_callable< T, P >,
#endif
has_result_type< T >,
has_result< T >,
has_sig< T >

View file

@ -9,22 +9,18 @@
#ifndef MOCK_MOVE_HELPER_HPP_INCLUDED
#define MOCK_MOVE_HELPER_HPP_INCLUDED
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/add_rvalue_reference.hpp>
#include <type_traits>
namespace mock
{
namespace detail
{
template< typename T >
struct ref_arg
{
typedef typename boost::conditional<
boost::is_reference< T >::value,
using ref_arg = std::conditional<
std::is_reference< T >::value,
T,
typename boost::add_rvalue_reference< T >::type >::type type;
};
std::add_rvalue_reference_t< T >
>;
}
}

View file

@ -12,11 +12,11 @@
#include "config.hpp"
#include "stream.hpp"
#include "format.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/detail/container_fwd.hpp>
#include <boost/function_types/is_callable_builtin.hpp>
#include <boost/none.hpp>
#include <memory>
#include <type_traits>
namespace boost
{
@ -181,19 +181,19 @@ namespace detail
#endif
template< typename T >
typename boost::enable_if<
boost::function_types::is_callable_builtin< T >,
std::enable_if_t<
boost::function_types::is_callable_builtin< T >::value,
stream&
>::type
>
operator<<( stream& s, T* )
{
return s << '?';
}
template< typename T >
typename boost::disable_if<
boost::function_types::is_callable_builtin< T >,
std::enable_if_t<
!boost::function_types::is_callable_builtin< T >::value,
stream&
>::type
>
operator<<( stream& s, T* t )
{
*s.s_ << t;

View file

@ -14,10 +14,9 @@
#include "constraints.hpp"
#include "detail/is_functor.hpp"
#include "detail/move_helper.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/ref.hpp>
#include <cstring>
#include <type_traits>
namespace mock
{
@ -28,7 +27,7 @@ namespace mock
explicit matcher( Expected expected )
: expected_( expected )
{}
bool operator()( typename boost::add_reference< const Actual >::type actual )
bool operator()( std::add_lvalue_reference_t< const Actual > actual )
{
return mock::equal(
boost::unwrap_ref( expected_ ) ).c_( actual );
@ -84,9 +83,9 @@ namespace mock
template< typename Actual, typename Functor >
class matcher< Actual, Functor,
typename boost::enable_if<
detail::is_functor< Functor, Actual >
>::type
std::enable_if_t<
detail::is_functor< Functor, Actual >::value
>
>
{
public:

View file

@ -28,7 +28,7 @@
struct T : mock::object
#define MOCK_FUNCTION_TYPE(S, tpn) \
tpn boost::remove_pointer< tpn BOOST_IDENTITY_TYPE(S) >::type
std::remove_pointer_t< tpn BOOST_IDENTITY_TYPE(S) >
#ifdef MOCK_VARIADIC_MACROS

View file

@ -14,10 +14,9 @@
#include "detail/type_name.hpp"
#include "detail/object_impl.hpp"
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/make_shared.hpp>
#include <boost/optional.hpp>
#include <type_traits>
namespace mock
{
@ -36,9 +35,7 @@ namespace detail
boost::unit_test::const_string instance,
boost::optional< type_name > type,
boost::unit_test::const_string name,
typename boost::disable_if<
typename boost::is_base_of< object, T >
>::type* = 0 )
std::enable_if_t< !std::is_base_of< object, T >::value >* = 0 )
{
e.configure( detail::root, &t, instance, type, name );
return e;

View file

@ -16,6 +16,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <type_traits>
// static
@ -23,14 +24,10 @@ namespace
{
boost::function< void() > static_f;
BOOST_MPL_ASSERT((
boost::is_same< void, boost::result_of< mock::detail::function< void() >() >::type > ));
BOOST_MPL_ASSERT((
boost::is_same< int, boost::result_of< mock::detail::function< int() >() >::type > ));
BOOST_MPL_ASSERT((
boost::is_same< void, boost::result_of< mock::detail::function< void( float ) >( float ) >::type > ));
BOOST_MPL_ASSERT((
boost::is_same< int, boost::result_of< mock::detail::function< int( float ) >( float ) >::type > ));
static_assert( std::is_same< void, boost::result_of< mock::detail::function< void() >() >::type >::value, "!");
static_assert( std::is_same< int, boost::result_of< mock::detail::function< int() >() >::type >::value, "!");
static_assert( std::is_same< void, boost::result_of< mock::detail::function< void( float ) >( float ) >::type >::value, "!");
static_assert( std::is_same< int, boost::result_of< mock::detail::function< int( float ) >( float ) >::type >::value, "!");
}
// functor

View file

@ -143,11 +143,7 @@ BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
{
is_not_functor( []() {} );
#ifdef MOCK_DECLTYPE
is_functor( []( int ) {} );
#else
is_not_functor( []( int ) {} );
#endif
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
}

View file

@ -8,7 +8,7 @@
#include <turtle/detail/signature.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
#include <type_traits>
namespace
{
@ -22,8 +22,6 @@ namespace
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{
BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE(method_1) > ));
BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE(method_2) > ));
static_assert( std::is_same< void(), MOCK_SIGNATURE(method_1) >::value, "!");
static_assert( std::is_same< float( int ), MOCK_SIGNATURE(method_2) >::value, "!");
}