]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/functional/logical.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / functional / logical.hpp
CommitLineData
7c673cae
FG
1//---------------------------------------------------------------------------//
2// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3//
4// Distributed under the Boost Software License, Version 1.0
5// See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt
7//
8// See http://boostorg.github.com/compute for more information.
9//---------------------------------------------------------------------------//
10
11#ifndef BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
12#define BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
13
14namespace boost {
15namespace compute {
16namespace detail {
17
18template<class Predicate, class Expr>
19class invoked_unary_negate_function
20{
21public:
22 typedef int result_type;
23
24 invoked_unary_negate_function(const Predicate &pred,
25 const Expr &expr)
26 : m_pred(pred),
27 m_expr(expr)
28 {
29 }
30
31 Predicate pred() const
32 {
33 return m_pred;
34 }
35
36 Expr expr() const
37 {
38 return m_expr;
39 }
40
41private:
42 Predicate m_pred;
43 Expr m_expr;
44};
45
46template<class Predicate, class Expr1, class Expr2>
47class invoked_binary_negate_function
48{
49public:
50 typedef int result_type;
51
52 invoked_binary_negate_function(const Predicate &pred,
53 const Expr1 &expr1,
54 const Expr2 &expr2)
55 : m_pred(pred),
56 m_expr1(expr1),
57 m_expr2(expr2)
58 {
59 }
60
61 Predicate pred() const
62 {
63 return m_pred;
64 }
65
66 Expr1 expr1() const
67 {
68 return m_expr1;
69 }
70
71 Expr2 expr2() const
72 {
73 return m_expr2;
74 }
75
76private:
77 Predicate m_pred;
78 Expr1 m_expr1;
79 Expr2 m_expr2;
80};
81
82} // end detail namespace
83
84/// \internal_
85template<class Arg, class Result>
86struct unary_function
87{
88 typedef Arg argument_type;
89 typedef Result result_type;
90};
91
92/// \internal_
93template<class Arg1, class Arg2, class Result>
94struct binary_function
95{
96 typedef Arg1 first_argument_type;
97 typedef Arg2 second_argument_type;
98 typedef Result result_type;
99};
100
101/// \internal_
102template<class Arg1, class Arg2, class Arg3, class Result>
103struct ternary_function
104{
105 typedef Arg1 first_argument_type;
106 typedef Arg2 second_argument_type;
107 typedef Arg3 third_argument_type;
108 typedef Result result_type;
109};
110
111/// The unary_negate function adaptor negates a unary function.
112///
113/// \see not1()
114template<class Predicate>
115class unary_negate : public unary_function<void, int>
116{
117public:
118 explicit unary_negate(Predicate pred)
119 : m_pred(pred)
120 {
121 }
122
123 /// \internal_
124 template<class Arg>
125 detail::invoked_unary_negate_function<Predicate, Arg>
126 operator()(const Arg &arg) const
127 {
128 return detail::invoked_unary_negate_function<
129 Predicate,
130 Arg
131 >(m_pred, arg);
132 }
133
134private:
135 Predicate m_pred;
136};
137
138/// The binnary_negate function adaptor negates a binary function.
139///
140/// \see not2()
141template<class Predicate>
142class binary_negate : public binary_function<void, void, int>
143{
144public:
145 explicit binary_negate(Predicate pred)
146 : m_pred(pred)
147 {
148 }
149
150 /// \internal_
151 template<class Arg1, class Arg2>
152 detail::invoked_binary_negate_function<Predicate, Arg1, Arg2>
153 operator()(const Arg1 &arg1, const Arg2 &arg2) const
154 {
155 return detail::invoked_binary_negate_function<
156 Predicate,
157 Arg1,
158 Arg2
159 >(m_pred, arg1, arg2);
160 }
161
162private:
163 Predicate m_pred;
164};
165
166/// Returns a unary_negate adaptor around \p predicate.
167///
168/// \param predicate the unary function to wrap
169///
170/// \return a unary_negate wrapper around \p predicate
171template<class Predicate>
172inline unary_negate<Predicate> not1(const Predicate &predicate)
173{
174 return unary_negate<Predicate>(predicate);
175}
176
177/// Returns a binary_negate adaptor around \p predicate.
178///
179/// \param predicate the binary function to wrap
180///
181/// \return a binary_negate wrapper around \p predicate
182template<class Predicate>
183inline binary_negate<Predicate> not2(const Predicate &predicate)
184{
185 return binary_negate<Predicate>(predicate);
186}
187
188/// The logical_not function negates its argument and returns it.
189///
190/// \see not1(), not2()
191template<class T>
192struct logical_not : public unary_function<T, int>
193{
194 /// \internal_
195 template<class Expr>
196 detail::invoked_function<int, boost::tuple<Expr> >
197 operator()(const Expr &expr) const
198 {
199 return detail::invoked_function<int, boost::tuple<Expr> >(
200 "!", std::string(), boost::make_tuple(expr)
201 );
202 }
203};
204
205} // end compute namespace
206} // end boost namespace
207
208#endif // BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP