Use make_* functions instead of new

This commit is contained in:
Alexander Grund 2020-07-14 19:33:00 +02:00
parent 558e1ca135
commit f3d6564d2b
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
3 changed files with 12 additions and 18 deletions

View file

@ -124,19 +124,19 @@ namespace detail
template< typename T > template< typename T >
T& store( T&& t ) T& store( T&& t )
{ {
v_.reset( new value_imp< T >( std::move( t ) ) ); v_ = std::make_shared< 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 >
T& store( const T& t ) T& store( const T& t )
{ {
v_.reset( new value_imp< T >( t ) ); v_ = std::make_shared< value_imp<T> >( t );
return static_cast< value_imp< T >& >( *v_ ).t_; return static_cast< value_imp< T >& >( *v_ ).t_;
} }
template< typename T > template< typename T >
std::remove_reference_t< Result >& store( T* t ) std::remove_reference_t< Result >& store( T* t )
{ {
v_.reset( new value_imp< Result >( t ) ); v_ = std::make_shared< value_imp<Result> >( t );
return static_cast< value_imp< Result >& >( *v_ ).t_; return static_cast< value_imp< Result >& >( *v_ ).t_;
} }

View file

@ -178,22 +178,22 @@ namespace detail
expectation& with( expectation& with(
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) ) BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
{ {
matcher_.reset( matcher_ = std::make_shared<
new single_matcher< single_matcher<
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ), void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
>( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) ) ); >>( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
return *this; return *this;
} }
#if MOCK_NUM_ARGS > 1 #if MOCK_NUM_ARGS > 1
template< typename Constraint > template< typename Constraint >
expectation& with( const Constraint& c ) expectation& with( const Constraint& c )
{ {
matcher_.reset( matcher_ = std::make_shared<
new multi_matcher< multi_matcher<
Constraint, Constraint,
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
>( c ) ); >>( c );
return *this; return *this;
} }
#endif #endif

View file

@ -10,6 +10,7 @@
#define MOCK_STREAM_HPP_INCLUDED #define MOCK_STREAM_HPP_INCLUDED
#include "config.hpp" #include "config.hpp"
#include <memory>
#include <ostream> #include <ostream>
namespace mock namespace mock
@ -69,16 +70,9 @@ namespace conversion
struct any struct any
{ {
template< typename T > template< typename T >
any( const T& t ) any( const T& t ): h_( std::make_unique< holder_imp<T> >( t ) )
: h_( new holder_imp< T >( t ) )
{} {}
any(const any&) = delete; std::unique_ptr<holder> h_;
any& operator=(const any&) = delete;
~any()
{
delete h_;
}
holder* h_;
}; };
} }
} }