Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // -- Boost Lambda Library ------------------------------------------------- |
| 2 | |
| 3 | // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // For more information, see www.boost.org |
| 10 | |
| 11 | // -------------------------------------------------- |
| 12 | |
| 13 | #ifndef BOOST_LAMBDA_ARITY_CODE_HPP |
| 14 | #define BOOST_LAMBDA_ARITY_CODE_HPP |
| 15 | |
| 16 | #include "ndnboost/type_traits/cv_traits.hpp" |
| 17 | #include "ndnboost/type_traits/transform_traits.hpp" |
| 18 | |
| 19 | namespace ndnboost { |
| 20 | namespace lambda { |
| 21 | |
| 22 | // These constants state, whether a lambda_functor instantiation results from |
| 23 | // an expression which contains no placeholders (NONE), |
| 24 | // only free1 placeholders (FIRST), |
| 25 | // free2 placeholders and maybe free1 placeholders (SECOND), |
| 26 | // free3 and maybe free1 and free2 placeholders (THIRD), |
| 27 | // freeE placeholders and maybe free1 and free2 (EXCEPTION). |
| 28 | // RETHROW means, that a rethrow expression is used somewhere in the lambda_functor. |
| 29 | |
| 30 | enum { NONE = 0x00, // Notice we are using bits as flags here. |
| 31 | FIRST = 0x01, |
| 32 | SECOND = 0x02, |
| 33 | THIRD = 0x04, |
| 34 | EXCEPTION = 0x08, |
| 35 | RETHROW = 0x10}; |
| 36 | |
| 37 | |
| 38 | template<class T> |
| 39 | struct get_tuple_arity; |
| 40 | |
| 41 | namespace detail { |
| 42 | |
| 43 | template <class T> struct get_arity_; |
| 44 | |
| 45 | } // end detail; |
| 46 | |
| 47 | template <class T> struct get_arity { |
| 48 | |
| 49 | BOOST_STATIC_CONSTANT(int, value = detail::get_arity_<typename ndnboost::remove_cv<typename ndnboost::remove_reference<T>::type>::type>::value); |
| 50 | |
| 51 | }; |
| 52 | |
| 53 | namespace detail { |
| 54 | |
| 55 | template<class T> |
| 56 | struct get_arity_ { |
| 57 | BOOST_STATIC_CONSTANT(int, value = 0); |
| 58 | }; |
| 59 | |
| 60 | template<class T> |
| 61 | struct get_arity_<lambda_functor<T> > { |
| 62 | BOOST_STATIC_CONSTANT(int, value = get_arity<T>::value); |
| 63 | }; |
| 64 | |
| 65 | template<class Action, class Args> |
| 66 | struct get_arity_<lambda_functor_base<Action, Args> > { |
| 67 | BOOST_STATIC_CONSTANT(int, value = get_tuple_arity<Args>::value); |
| 68 | }; |
| 69 | |
| 70 | template<int I> |
| 71 | struct get_arity_<placeholder<I> > { |
| 72 | BOOST_STATIC_CONSTANT(int, value = I); |
| 73 | }; |
| 74 | |
| 75 | } // detail |
| 76 | |
| 77 | template<class T> |
| 78 | struct get_tuple_arity { |
| 79 | BOOST_STATIC_CONSTANT(int, value = get_arity<typename T::head_type>::value | get_tuple_arity<typename T::tail_type>::value); |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | template<> |
| 84 | struct get_tuple_arity<null_type> { |
| 85 | BOOST_STATIC_CONSTANT(int, value = 0); |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | // Does T have placeholder<I> as it's subexpression? |
| 90 | |
| 91 | template<class T, int I> |
| 92 | struct has_placeholder { |
| 93 | BOOST_STATIC_CONSTANT(bool, value = (get_arity<T>::value & I) != 0); |
| 94 | }; |
| 95 | |
| 96 | template<int I, int J> |
| 97 | struct includes_placeholder { |
| 98 | BOOST_STATIC_CONSTANT(bool, value = (J & I) != 0); |
| 99 | }; |
| 100 | |
| 101 | template<int I, int J> |
| 102 | struct lacks_placeholder { |
| 103 | BOOST_STATIC_CONSTANT(bool, value = ((J & I) == 0)); |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | } // namespace lambda |
| 108 | } // namespace ndnboost |
| 109 | |
| 110 | #endif |