Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
0012 #define BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
0013 
0014 namespace boost {
0015 namespace compute {
0016 namespace detail {
0017 
0018 template<class Predicate, class Expr>
0019 class invoked_unary_negate_function
0020 {
0021 public:
0022     typedef int result_type;
0023 
0024     invoked_unary_negate_function(const Predicate &pred,
0025                                   const Expr &expr)
0026         : m_pred(pred),
0027           m_expr(expr)
0028     {
0029     }
0030 
0031     Predicate pred() const
0032     {
0033         return m_pred;
0034     }
0035 
0036     Expr expr() const
0037     {
0038         return m_expr;
0039     }
0040 
0041 private:
0042     Predicate m_pred;
0043     Expr m_expr;
0044 };
0045 
0046 template<class Predicate, class Expr1, class Expr2>
0047 class invoked_binary_negate_function
0048 {
0049 public:
0050     typedef int result_type;
0051 
0052     invoked_binary_negate_function(const Predicate &pred,
0053                                    const Expr1 &expr1,
0054                                    const Expr2 &expr2)
0055         : m_pred(pred),
0056           m_expr1(expr1),
0057           m_expr2(expr2)
0058     {
0059     }
0060 
0061     Predicate pred() const
0062     {
0063         return m_pred;
0064     }
0065 
0066     Expr1 expr1() const
0067     {
0068         return m_expr1;
0069     }
0070 
0071     Expr2 expr2() const
0072     {
0073         return m_expr2;
0074     }
0075 
0076 private:
0077     Predicate m_pred;
0078     Expr1 m_expr1;
0079     Expr2 m_expr2;
0080 };
0081 
0082 } // end detail namespace
0083 
0084 /// \internal_
0085 template<class Arg, class Result>
0086 struct unary_function
0087 {
0088     typedef Arg argument_type;
0089     typedef Result result_type;
0090 };
0091 
0092 /// \internal_
0093 template<class Arg1, class Arg2, class Result>
0094 struct binary_function
0095 {
0096     typedef Arg1 first_argument_type;
0097     typedef Arg2 second_argument_type;
0098     typedef Result result_type;
0099 };
0100 
0101 /// \internal_
0102 template<class Arg1, class Arg2, class Arg3, class Result>
0103 struct ternary_function
0104 {
0105     typedef Arg1 first_argument_type;
0106     typedef Arg2 second_argument_type;
0107     typedef Arg3 third_argument_type;
0108     typedef Result result_type;
0109 };
0110 
0111 /// The unary_negate function adaptor negates a unary function.
0112 ///
0113 /// \see not1()
0114 template<class Predicate>
0115 class unary_negate : public unary_function<void, int>
0116 {
0117 public:
0118     explicit unary_negate(Predicate pred)
0119         : m_pred(pred)
0120     {
0121     }
0122 
0123     /// \internal_
0124     template<class Arg>
0125     detail::invoked_unary_negate_function<Predicate, Arg>
0126     operator()(const Arg &arg) const
0127     {
0128         return detail::invoked_unary_negate_function<
0129                    Predicate,
0130                    Arg
0131                 >(m_pred, arg);
0132     }
0133 
0134 private:
0135     Predicate m_pred;
0136 };
0137 
0138 /// The binnary_negate function adaptor negates a binary function.
0139 ///
0140 /// \see not2()
0141 template<class Predicate>
0142 class binary_negate : public binary_function<void, void, int>
0143 {
0144 public:
0145     explicit binary_negate(Predicate pred)
0146         : m_pred(pred)
0147     {
0148     }
0149 
0150     /// \internal_
0151     template<class Arg1, class Arg2>
0152     detail::invoked_binary_negate_function<Predicate, Arg1, Arg2>
0153     operator()(const Arg1 &arg1, const Arg2 &arg2) const
0154     {
0155         return detail::invoked_binary_negate_function<
0156                    Predicate,
0157                    Arg1,
0158                    Arg2
0159                 >(m_pred, arg1, arg2);
0160     }
0161 
0162 private:
0163     Predicate m_pred;
0164 };
0165 
0166 /// Returns a unary_negate adaptor around \p predicate.
0167 ///
0168 /// \param predicate the unary function to wrap
0169 ///
0170 /// \return a unary_negate wrapper around \p predicate
0171 template<class Predicate>
0172 inline unary_negate<Predicate> not1(const Predicate &predicate)
0173 {
0174     return unary_negate<Predicate>(predicate);
0175 }
0176 
0177 /// Returns a binary_negate adaptor around \p predicate.
0178 ///
0179 /// \param predicate the binary function to wrap
0180 ///
0181 /// \return a binary_negate wrapper around \p predicate
0182 template<class Predicate>
0183 inline binary_negate<Predicate> not2(const Predicate &predicate)
0184 {
0185     return binary_negate<Predicate>(predicate);
0186 }
0187 
0188 /// The logical_not function negates its argument and returns it.
0189 ///
0190 /// \see not1(), not2()
0191 template<class T>
0192 struct logical_not : public unary_function<T, int>
0193 {
0194     /// \internal_
0195     template<class Expr>
0196     detail::invoked_function<int, boost::tuple<Expr> >
0197     operator()(const Expr &expr) const
0198     {
0199         return detail::invoked_function<int, boost::tuple<Expr> >(
0200             "!", std::string(), boost::make_tuple(expr)
0201         );
0202     }
0203 };
0204 
0205 } // end compute namespace
0206 } // end boost namespace
0207 
0208 #endif // BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP