Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:08

0001 // Boost Lambda Library  - operator_lambda_func_base.hpp -----------------
0002 //
0003 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // For more information, see www.boost.org
0010 
0011 // ------------------------------------------------------------
0012 
0013 #ifndef BOOST_LAMBDA_OPERATOR_LAMBDA_FUNC_BASE_HPP
0014 #define BOOST_LAMBDA_OPERATOR_LAMBDA_FUNC_BASE_HPP
0015 
0016 namespace boost { 
0017 namespace lambda {
0018 
0019 
0020 // These operators cannot be implemented as apply functions of action 
0021 // templates
0022 
0023 
0024 // Specialization for comma.
0025 template<class Args>
0026 class lambda_functor_base<other_action<comma_action>, Args> {
0027 public:
0028   Args args;
0029 public:
0030   explicit lambda_functor_base(const Args& a) : args(a) {}
0031 
0032   template<class RET, CALL_TEMPLATE_ARGS>
0033   RET call(CALL_FORMAL_ARGS) const {
0034     return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS), 
0035            detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); 
0036   }
0037 
0038 
0039   template<class SigArgs> struct sig { 
0040   private:
0041     typedef typename
0042       detail::deduce_argument_types<Args, SigArgs>::type rets_t;      
0043   public:
0044     typedef typename return_type_2_comma< // comma needs special handling
0045       typename detail::element_or_null<0, rets_t>::type,
0046       typename detail::element_or_null<1, rets_t>::type
0047     >::type type;
0048   };
0049 
0050 };  
0051 
0052 namespace detail {
0053 
0054 // helper traits to make the expression shorter, takes binary action
0055 // bound argument tuple, open argument tuple and gives the return type
0056 
0057 template<class Action, class Bound, class Open> class binary_rt {
0058   private:
0059     typedef typename
0060       detail::deduce_argument_types<Bound, Open>::type rets_t;      
0061   public:
0062     typedef typename return_type_2_prot<
0063       Action,  
0064       typename detail::element_or_null<0, rets_t>::type,
0065       typename detail::element_or_null<1, rets_t>::type
0066     >::type type;
0067 };
0068 
0069 
0070   // same for unary actions
0071 template<class Action, class Bound, class Open> class unary_rt {
0072   private:
0073     typedef typename
0074       detail::deduce_argument_types<Bound, Open>::type rets_t;      
0075   public:
0076     typedef typename return_type_1_prot<
0077       Action,  
0078       typename detail::element_or_null<0, rets_t>::type
0079     >::type type;
0080 };
0081 
0082 
0083 } // end detail
0084 
0085 // Specialization for logical and (to preserve shortcircuiting)
0086 // this could be done with a macro as the others, code used to be different
0087 template<class Args>
0088 class lambda_functor_base<logical_action<and_action>, Args> {
0089 public:
0090   Args args;
0091 public:
0092   explicit lambda_functor_base(const Args& a) : args(a) {}
0093 
0094   template<class RET, CALL_TEMPLATE_ARGS>
0095   RET call(CALL_FORMAL_ARGS) const {
0096     return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) && 
0097            detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); 
0098   }
0099   template<class SigArgs> struct sig { 
0100     typedef typename
0101       detail::binary_rt<logical_action<and_action>, Args, SigArgs>::type type;
0102   };      
0103 };  
0104 
0105 // Specialization for logical or (to preserve shortcircuiting)
0106 // this could be done with a macro as the others, code used to be different
0107 template<class Args>
0108 class lambda_functor_base<logical_action< or_action>, Args> {
0109 public:
0110   Args args;
0111 public:
0112   explicit lambda_functor_base(const Args& a) : args(a) {}
0113 
0114   template<class RET, CALL_TEMPLATE_ARGS>
0115   RET call(CALL_FORMAL_ARGS) const {
0116     return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) || 
0117            detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); 
0118   }
0119 
0120   template<class SigArgs> struct sig { 
0121     typedef typename
0122       detail::binary_rt<logical_action<or_action>, Args, SigArgs>::type type;
0123   };      
0124 };  
0125 
0126 // Specialization for subscript
0127 template<class Args>
0128 class lambda_functor_base<other_action<subscript_action>, Args> {
0129 public:
0130   Args args;
0131 public:
0132   explicit lambda_functor_base(const Args& a) : args(a) {}
0133 
0134   template<class RET, CALL_TEMPLATE_ARGS>
0135   RET call(CALL_FORMAL_ARGS) const {
0136     return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) 
0137            [detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS)]; 
0138   }
0139 
0140   template<class SigArgs> struct sig { 
0141     typedef typename
0142       detail::binary_rt<other_action<subscript_action>, Args, SigArgs>::type 
0143         type;
0144   };      
0145 };  
0146 
0147 
0148 #define BOOST_LAMBDA_BINARY_ACTION(SYMBOL, ACTION_CLASS)  \
0149 template<class Args>                                                      \
0150 class lambda_functor_base<ACTION_CLASS, Args> {                           \
0151 public:                                                                   \
0152   Args args;                                                              \
0153 public:                                                                   \
0154   explicit lambda_functor_base(const Args& a) : args(a) {}                \
0155                                                                           \
0156   template<class RET, CALL_TEMPLATE_ARGS>                                 \
0157   RET call(CALL_FORMAL_ARGS) const {                                      \
0158     return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)  \
0159            SYMBOL                                                         \
0160            detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); \
0161   }                                                                       \
0162   template<class SigArgs> struct sig {                                    \
0163     typedef typename                                                      \
0164       detail::binary_rt<ACTION_CLASS, Args, SigArgs>::type type;          \
0165   };                                                                      \
0166 };  
0167 
0168 #define BOOST_LAMBDA_PREFIX_UNARY_ACTION(SYMBOL, ACTION_CLASS)            \
0169 template<class Args>                                                      \
0170 class lambda_functor_base<ACTION_CLASS, Args> {                           \
0171 public:                                                                   \
0172   Args args;                                                              \
0173 public:                                                                   \
0174   explicit lambda_functor_base(const Args& a) : args(a) {}                \
0175                                                                           \
0176   template<class RET, CALL_TEMPLATE_ARGS>                                 \
0177   RET call(CALL_FORMAL_ARGS) const {                                      \
0178     return SYMBOL                                                         \
0179            detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS); \
0180   }                                                                       \
0181   template<class SigArgs> struct sig {                                    \
0182     typedef typename                                                      \
0183       detail::unary_rt<ACTION_CLASS, Args, SigArgs>::type type;           \
0184   };                                                                      \
0185 };  
0186 
0187 #define BOOST_LAMBDA_POSTFIX_UNARY_ACTION(SYMBOL, ACTION_CLASS)           \
0188 template<class Args>                                                      \
0189 class lambda_functor_base<ACTION_CLASS, Args> {                           \
0190 public:                                                                   \
0191   Args args;                                                              \
0192 public:                                                                   \
0193   explicit lambda_functor_base(const Args& a) : args(a) {}                \
0194                                                                           \
0195   template<class RET, CALL_TEMPLATE_ARGS>                                 \
0196   RET call(CALL_FORMAL_ARGS) const {                                      \
0197     return                                                                \
0198     detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) SYMBOL; \
0199   }                                                                       \
0200   template<class SigArgs> struct sig {                                    \
0201     typedef typename                                                      \
0202       detail::unary_rt<ACTION_CLASS, Args, SigArgs>::type type;           \
0203   };                                                                      \
0204 };  
0205 
0206 BOOST_LAMBDA_BINARY_ACTION(+,arithmetic_action<plus_action>)
0207 BOOST_LAMBDA_BINARY_ACTION(-,arithmetic_action<minus_action>)
0208 BOOST_LAMBDA_BINARY_ACTION(*,arithmetic_action<multiply_action>)
0209 BOOST_LAMBDA_BINARY_ACTION(/,arithmetic_action<divide_action>)
0210 BOOST_LAMBDA_BINARY_ACTION(%,arithmetic_action<remainder_action>)
0211 
0212 BOOST_LAMBDA_BINARY_ACTION(<<,bitwise_action<leftshift_action>)
0213 BOOST_LAMBDA_BINARY_ACTION(>>,bitwise_action<rightshift_action>)
0214 BOOST_LAMBDA_BINARY_ACTION(&,bitwise_action<and_action>)
0215 BOOST_LAMBDA_BINARY_ACTION(|,bitwise_action<or_action>)
0216 BOOST_LAMBDA_BINARY_ACTION(^,bitwise_action<xor_action>)
0217 
0218 BOOST_LAMBDA_BINARY_ACTION(<,relational_action<less_action>)
0219 BOOST_LAMBDA_BINARY_ACTION(>,relational_action<greater_action>)
0220 BOOST_LAMBDA_BINARY_ACTION(<=,relational_action<lessorequal_action>)
0221 BOOST_LAMBDA_BINARY_ACTION(>=,relational_action<greaterorequal_action>)
0222 BOOST_LAMBDA_BINARY_ACTION(==,relational_action<equal_action>)
0223 BOOST_LAMBDA_BINARY_ACTION(!=,relational_action<notequal_action>)
0224 
0225 BOOST_LAMBDA_BINARY_ACTION(+=,arithmetic_assignment_action<plus_action>)
0226 BOOST_LAMBDA_BINARY_ACTION(-=,arithmetic_assignment_action<minus_action>)
0227 BOOST_LAMBDA_BINARY_ACTION(*=,arithmetic_assignment_action<multiply_action>)
0228 BOOST_LAMBDA_BINARY_ACTION(/=,arithmetic_assignment_action<divide_action>)
0229 BOOST_LAMBDA_BINARY_ACTION(%=,arithmetic_assignment_action<remainder_action>)
0230 
0231 BOOST_LAMBDA_BINARY_ACTION(<<=,bitwise_assignment_action<leftshift_action>)
0232 BOOST_LAMBDA_BINARY_ACTION(>>=,bitwise_assignment_action<rightshift_action>)
0233 BOOST_LAMBDA_BINARY_ACTION(&=,bitwise_assignment_action<and_action>)
0234 BOOST_LAMBDA_BINARY_ACTION(|=,bitwise_assignment_action<or_action>)
0235 BOOST_LAMBDA_BINARY_ACTION(^=,bitwise_assignment_action<xor_action>)
0236 
0237 BOOST_LAMBDA_BINARY_ACTION(=,other_action< assignment_action>)
0238 
0239 
0240 BOOST_LAMBDA_PREFIX_UNARY_ACTION(+, unary_arithmetic_action<plus_action>)
0241 BOOST_LAMBDA_PREFIX_UNARY_ACTION(-, unary_arithmetic_action<minus_action>)
0242 BOOST_LAMBDA_PREFIX_UNARY_ACTION(~, bitwise_action<not_action>)
0243 BOOST_LAMBDA_PREFIX_UNARY_ACTION(!, logical_action<not_action>)
0244 BOOST_LAMBDA_PREFIX_UNARY_ACTION(++, pre_increment_decrement_action<increment_action>)
0245 BOOST_LAMBDA_PREFIX_UNARY_ACTION(--, pre_increment_decrement_action<decrement_action>)
0246 
0247 BOOST_LAMBDA_PREFIX_UNARY_ACTION(&,other_action<addressof_action>)
0248 BOOST_LAMBDA_PREFIX_UNARY_ACTION(*,other_action<contentsof_action>)
0249 
0250 BOOST_LAMBDA_POSTFIX_UNARY_ACTION(++, post_increment_decrement_action<increment_action>)
0251 BOOST_LAMBDA_POSTFIX_UNARY_ACTION(--, post_increment_decrement_action<decrement_action>)
0252 
0253 
0254 #undef BOOST_LAMBDA_POSTFIX_UNARY_ACTION
0255 #undef BOOST_LAMBDA_PREFIX_UNARY_ACTION
0256 #undef BOOST_LAMBDA_BINARY_ACTION
0257 
0258 } // namespace lambda
0259 } // namespace boost
0260 
0261 #endif
0262 
0263 
0264 
0265 
0266 
0267 
0268 
0269 
0270 
0271