Use std::reference_wrapper instead of boost

This commit is contained in:
Alexander Grund 2020-07-09 20:25:40 +02:00
parent 353849e9ad
commit 35e43d58a6
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
16 changed files with 116 additions and 90 deletions

View file

@ -11,7 +11,7 @@
#include "config.hpp"
#include "log.hpp"
#include <boost/ref.hpp>
#include "detail/unwrap_reference.hpp"
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/variadic/to_array.hpp>
@ -19,6 +19,7 @@
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/array.hpp>
#include <functional>
#include <type_traits>
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) \

View file

@ -12,7 +12,7 @@
#include "config.hpp"
#include "constraint.hpp"
#include "detail/move_helper.hpp"
#include <boost/ref.hpp>
#include "detail/unwrap_reference.hpp"
#include <boost/version.hpp>
#include <boost/type_traits/make_void.hpp>
#if BOOST_VERSION >= 107000
@ -20,6 +20,7 @@
#else
#include <boost/test/floating_point_comparison.hpp>
#endif
#include <functional>
#include <memory>
#include <type_traits>
@ -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 )

View file

@ -11,7 +11,6 @@
#include "../config.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <functional>
#include <memory>
#include <type_traits>
@ -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 );
}

View file

@ -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 );
}

View file

@ -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 <functional>
#include <type_traits>
namespace mock
{
namespace detail
{
template<class T>
struct unwrap_reference
{
using type = T;
};
template<class T>
struct unwrap_reference<std::reference_wrapper<T>>
{
using type = T;
};
template<class T>
struct unwrap_reference<const std::reference_wrapper<T>>
{
using type = T;
};
template<class T>
using unwrap_reference_t = typename unwrap_reference<T>::type;
template<class T>
BOOST_FORCEINLINE unwrap_reference_t<T>& unwrap_ref( T& t ) noexcept
{
return t;
}
}
}
#endif // MOCK_UNWRAP_REFERENCE_HPP_INCLUDED

View file

@ -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() );

View file

@ -14,8 +14,8 @@
#include "constraints.hpp"
#include "detail/is_functor.hpp"
#include "detail/move_helper.hpp"
#include <boost/ref.hpp>
#include <cstring>
#include <functional>
#include <type_traits>
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 )