-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.hpp
77 lines (70 loc) · 1.84 KB
/
lambda.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Copyright Mathieu Champlon 2011
//
// 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_LAMBDA_HPP_INCLUDED
#define MOCK_LAMBDA_HPP_INCLUDED
#include "config.hpp"
#ifdef MOCK_USE_BOOST_PHOENIX
#include <boost/spirit/home/phoenix/bind.hpp>
#else
#include <boost/bind.hpp>
#endif
#include <boost/function.hpp>
namespace mock
{
namespace detail
{
#ifdef MOCK_USE_BOOST_PHOENIX
using boost::phoenix::bind;
#else
using boost::bind;
#endif
template< typename Result, typename Signature >
struct lambda
{
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
template< typename T >
static functor_type make_val( T t )
{
return mock::detail::bind( &do_identity< T >, t );
}
template< typename T >
static functor_type make_val( boost::reference_wrapper< T > t )
{
return mock::detail::bind( &do_ref_identity< T >, t.get_pointer() );
}
template< typename T >
static functor_type make_throw( T t )
{
return mock::detail::bind( &do_throw< T >, t );
}
static functor_type make_nothing()
{
return mock::detail::bind( &do_nothing );
}
template< typename T >
static T do_identity( T t )
{
return t;
}
template< typename T >
static T& do_ref_identity( T* t )
{
return *t;
}
template< typename T >
static Result do_throw( T t )
{
throw t;
}
static void do_nothing()
{}
};
}
}
#endif // MOCK_LAMBDA_HPP_INCLUDED