]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/include/boost/phoenix/core/function_equal.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / phoenix / include / boost / phoenix / core / function_equal.hpp
1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Thomas Heller
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #ifndef BOOST_PHOENIX_CORE_FUNCTION_EQUAL_HPP
9 #define BOOST_PHOENIX_CORE_FUNCTION_EQUAL_HPP
10
11 #include <boost/phoenix/core/limits.hpp>
12 #include <boost/is_placeholder.hpp>
13 #include <boost/mpl/bool.hpp>
14 #include <boost/phoenix/core/terminal.hpp>
15 #include <boost/proto/matches.hpp>
16
17 #ifndef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EQUAL
18 # include <boost/phoenix/core/detail/index_sequence.hpp>
19 #endif
20
21 namespace boost
22 {
23 template <typename> class weak_ptr;
24 }
25
26 namespace boost { namespace phoenix
27 {
28 template <typename>
29 struct actor;
30
31 namespace detail
32 {
33 struct compare
34 : proto::callable
35 {
36 typedef bool result_type;
37
38 template <typename A0, typename A1>
39 result_type operator()(A0 const & a0, A1 const & a1) const
40 {
41 return a0 == a1;
42 }
43
44 // hard wiring reference_wrapper and weak_ptr here ...
45 // **TODO** find out why boost bind does this ...
46 template <typename A0, typename A1>
47 result_type
48 operator()(
49 reference_wrapper<A0> const & a0
50 , reference_wrapper<A1> const & a1
51 ) const
52 {
53 return a0.get_pointer() == a1.get_pointer();
54 }
55
56 template <typename A0, typename A1>
57 result_type
58 operator()(weak_ptr<A0> const & a0, weak_ptr<A1> const & a1) const
59 {
60 return !(a0 < a1) && !(a1 < a0);
61 }
62 };
63
64 struct function_equal_otherwise;
65
66 struct function_equal_
67 : proto::when<
68 proto::if_<
69 proto::matches<proto::_, proto::_state>()
70 , proto::or_<
71 proto::when<
72 proto::terminal<proto::_>
73 , compare(
74 proto::_value
75 , proto::call<
76 proto::_value(proto::_state)
77 >
78 )
79 >
80 , proto::otherwise<function_equal_otherwise(proto::_, proto::_state)>
81 >
82 , proto::call<function_equal_otherwise()>
83 >
84 >
85 {};
86
87 struct function_equal_otherwise
88 : proto::callable
89 {
90 typedef bool result_type;
91
92 result_type operator()() const
93 {
94 return false;
95 }
96
97 #ifdef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EQUAL
98 template <typename Expr1>
99 result_type operator()(Expr1 const& e1, Expr1 const& e2) const
100 {
101 return
102 this->evaluate(
103 e1
104 , e2
105 , typename proto::arity_of<Expr1>::type()
106 );
107 }
108
109 private:
110 #include <boost/phoenix/core/detail/cpp03/function_equal.hpp>
111 #else
112 template <typename Expr1>
113 result_type operator()(Expr1 const& e1, Expr1 const& e2) const
114 {
115 return
116 this->evaluate(
117 e1
118 , e2
119 , typename make_index_sequence<proto::arity_of<Expr1>::value>::type()
120 );
121 }
122
123 private:
124 template <typename Expr1>
125 result_type
126 evaluate(Expr1 const& /*e1*/, Expr1 const& /*e2*/, index_sequence<>) const
127 {
128 return true;
129 }
130 template <typename Expr1, std::size_t Head, std::size_t... Tail>
131 result_type
132 evaluate(Expr1 const& e1, Expr1 const& e2, index_sequence<Head, Tail...>) const
133 {
134 return
135 function_equal_()(proto::child_c<Head>(e1), proto::child_c<Head>(e2)) &&
136 this->evaluate(
137 e1
138 , e2
139 , index_sequence<Tail...>()
140 );
141 }
142 #endif
143 };
144 }
145
146 template <typename Expr1, typename Expr2>
147 inline bool function_equal_impl(actor<Expr1> const& a1, actor<Expr2> const& a2)
148 {
149 return detail::function_equal_()(a1, a2);
150 }
151
152 template <typename Expr1, typename Expr2>
153 inline bool function_equal(actor<Expr1> const& a1, actor<Expr2> const& a2)
154 {
155 return function_equal_impl(a1, a2);
156 }
157
158 }}
159
160 #endif
161