Added support for nullptr as constraint

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@648 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-05-12 08:59:25 +00:00
parent 42c2c4e6a4
commit 1320a96179
12 changed files with 96 additions and 10 deletions

View file

@ -11,6 +11,7 @@
#include "config.hpp"
#include "constraint.hpp"
#include "detail/addressof.hpp"
#include <boost/ref.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/addressof.hpp>
@ -35,12 +36,12 @@ namespace detail
struct same
{
explicit same( const Expected& expected )
: expected_( boost::addressof( boost::unwrap_ref( expected ) ) )
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
{}
template< typename Actual >
bool operator()( const Actual& actual ) const
{
return boost::addressof( actual ) == expected_;
return detail::addressof( actual ) == expected_;
}
friend std::ostream& operator<<( std::ostream& os, const same& s )
{
@ -54,7 +55,7 @@ namespace detail
struct retrieve
{
explicit retrieve( Expected& expected )
: expected_( boost::addressof( boost::unwrap_ref( expected ) ) )
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
{}
template< typename Actual >
bool operator()( const Actual& actual,
@ -78,7 +79,7 @@ namespace detail
>
>::type* = 0 ) const
{
*expected_ = boost::addressof( actual );
*expected_ = detail::addressof( actual );
return true;
}
friend std::ostream& operator<<( std::ostream& s, const retrieve& r )

View file

@ -0,0 +1,35 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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_ADDRESSOF_HPP_INCLUDED
#define MOCK_ADDRESSOF_HPP_INCLUDED
#include <boost/utility/addressof.hpp>
namespace mock
{
namespace detail
{
using boost::addressof;
#if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR)
inline const std::nullptr_t* addressof( const std::nullptr_t& p )
{
return &p;
}
inline std::nullptr_t* addressof( std::nullptr_t& p )
{
return &p;
}
#endif
}
} // mock
#endif // MOCK_ADDRESSOF_HPP_INCLUDED

View file

@ -11,7 +11,7 @@
#include "../config.hpp"
#include "../stream.hpp"
#include <boost/utility/addressof.hpp>
#include "addressof.hpp"
namespace mock
{
@ -21,7 +21,7 @@ namespace detail
struct formatter
{
explicit formatter( const T& t )
: t_( boost::addressof( t ) )
: t_( detail::addressof( t ) )
{}
void serialize( stream& s ) const
{

View file

@ -137,6 +137,13 @@ namespace detail
{
return s << '?';
}
#if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR)
inline stream& operator<<( stream& s, std::nullptr_t )
{
return s << "nullptr";
}
#endif
template< typename T >
BOOST_DEDUCED_TYPENAME boost::enable_if<
boost::function_types::is_callable_builtin< T >,

View file

@ -10,7 +10,6 @@
#define MOCK_STREAM_HPP_INCLUDED
#include "config.hpp"
#include <boost/utility/addressof.hpp>
#include <boost/noncopyable.hpp>
#include <ostream>
@ -53,16 +52,16 @@ namespace conversion
struct holder_imp : holder
{
explicit holder_imp( const T& t )
: t_( boost::addressof( t ) )
: t_( t )
{}
virtual void serialize( std::ostream& s ) const
{
// if an error about an ambiguous conversion is generated by the
// line below the solution is to add a serialization operator to a
// mock::stream for T
s << *t_;
s << t_;
}
const T* t_;
const T& t_;
};
struct any : boost::noncopyable