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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 13 | #ifndef NDNBOOST_LAMBDA_ARITY_CODE_HPP |
| 14 | #define NDNBOOST_LAMBDA_ARITY_CODE_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 49 | NDNBOOST_STATIC_CONSTANT(int, value = detail::get_arity_<typename ndnboost::remove_cv<typename ndnboost::remove_reference<T>::type>::type>::value); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 50 | |
| 51 | }; |
| 52 | |
| 53 | namespace detail { |
| 54 | |
| 55 | template<class T> |
| 56 | struct get_arity_ { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 57 | NDNBOOST_STATIC_CONSTANT(int, value = 0); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | template<class T> |
| 61 | struct get_arity_<lambda_functor<T> > { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 62 | NDNBOOST_STATIC_CONSTANT(int, value = get_arity<T>::value); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | template<class Action, class Args> |
| 66 | struct get_arity_<lambda_functor_base<Action, Args> > { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 67 | NDNBOOST_STATIC_CONSTANT(int, value = get_tuple_arity<Args>::value); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | template<int I> |
| 71 | struct get_arity_<placeholder<I> > { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 72 | NDNBOOST_STATIC_CONSTANT(int, value = I); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // detail |
| 76 | |
| 77 | template<class T> |
| 78 | struct get_tuple_arity { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 79 | NDNBOOST_STATIC_CONSTANT(int, value = get_arity<typename T::head_type>::value | get_tuple_arity<typename T::tail_type>::value); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | |
| 83 | template<> |
| 84 | struct get_tuple_arity<null_type> { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 85 | NDNBOOST_STATIC_CONSTANT(int, value = 0); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | |
| 89 | // Does T have placeholder<I> as it's subexpression? |
| 90 | |
| 91 | template<class T, int I> |
| 92 | struct has_placeholder { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | NDNBOOST_STATIC_CONSTANT(bool, value = (get_arity<T>::value & I) != 0); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | template<int I, int J> |
| 97 | struct includes_placeholder { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 98 | NDNBOOST_STATIC_CONSTANT(bool, value = (J & I) != 0); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | template<int I, int J> |
| 102 | struct lacks_placeholder { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 103 | NDNBOOST_STATIC_CONSTANT(bool, value = ((J & I) == 0)); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | |
| 107 | } // namespace lambda |
| 108 | } // namespace ndnboost |
| 109 | |
| 110 | #endif |