1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
12 #define BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
18 template<class Predicate, class Expr>
19 class invoked_unary_negate_function
22 typedef int result_type;
24 invoked_unary_negate_function(const Predicate &pred,
31 Predicate pred() const
46 template<class Predicate, class Expr1, class Expr2>
47 class invoked_binary_negate_function
50 typedef int result_type;
52 invoked_binary_negate_function(const Predicate &pred,
61 Predicate pred() const
82 } // end detail namespace
85 template<class Arg, class Result>
88 typedef Arg argument_type;
89 typedef Result result_type;
93 template<class Arg1, class Arg2, class Result>
94 struct binary_function
96 typedef Arg1 first_argument_type;
97 typedef Arg2 second_argument_type;
98 typedef Result result_type;
102 template<class Arg1, class Arg2, class Arg3, class Result>
103 struct ternary_function
105 typedef Arg1 first_argument_type;
106 typedef Arg2 second_argument_type;
107 typedef Arg3 third_argument_type;
108 typedef Result result_type;
111 /// The unary_negate function adaptor negates a unary function.
114 template<class Predicate>
115 class unary_negate : public unary_function<void, int>
118 explicit unary_negate(Predicate pred)
125 detail::invoked_unary_negate_function<Predicate, Arg>
126 operator()(const Arg &arg) const
128 return detail::invoked_unary_negate_function<
138 /// The binnary_negate function adaptor negates a binary function.
141 template<class Predicate>
142 class binary_negate : public binary_function<void, void, int>
145 explicit binary_negate(Predicate pred)
151 template<class Arg1, class Arg2>
152 detail::invoked_binary_negate_function<Predicate, Arg1, Arg2>
153 operator()(const Arg1 &arg1, const Arg2 &arg2) const
155 return detail::invoked_binary_negate_function<
159 >(m_pred, arg1, arg2);
166 /// Returns a unary_negate adaptor around \p predicate.
168 /// \param predicate the unary function to wrap
170 /// \return a unary_negate wrapper around \p predicate
171 template<class Predicate>
172 inline unary_negate<Predicate> not1(const Predicate &predicate)
174 return unary_negate<Predicate>(predicate);
177 /// Returns a binary_negate adaptor around \p predicate.
179 /// \param predicate the binary function to wrap
181 /// \return a binary_negate wrapper around \p predicate
182 template<class Predicate>
183 inline binary_negate<Predicate> not2(const Predicate &predicate)
185 return binary_negate<Predicate>(predicate);
188 /// The logical_not function negates its argument and returns it.
190 /// \see not1(), not2()
192 struct logical_not : public unary_function<T, int>
196 detail::invoked_function<int, boost::tuple<Expr> >
197 operator()(const Expr &expr) const
199 return detail::invoked_function<int, boost::tuple<Expr> >(
200 "!", std::string(), boost::make_tuple(expr)
205 } // end compute namespace
206 } // end boost namespace
208 #endif // BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP