blob: 2b762c35c274bafe96a2ea88da04fd92b71ffc3e [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// -- 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
19namespace ndnboost {
20namespace 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
30enum { 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
38template<class T>
39struct get_tuple_arity;
40
41namespace detail {
42
43template <class T> struct get_arity_;
44
45} // end detail;
46
47template <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
53namespace detail {
54
55template<class T>
56struct get_arity_ {
57 BOOST_STATIC_CONSTANT(int, value = 0);
58};
59
60template<class T>
61struct get_arity_<lambda_functor<T> > {
62 BOOST_STATIC_CONSTANT(int, value = get_arity<T>::value);
63};
64
65template<class Action, class Args>
66struct get_arity_<lambda_functor_base<Action, Args> > {
67 BOOST_STATIC_CONSTANT(int, value = get_tuple_arity<Args>::value);
68};
69
70template<int I>
71struct get_arity_<placeholder<I> > {
72 BOOST_STATIC_CONSTANT(int, value = I);
73};
74
75} // detail
76
77template<class T>
78struct 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
83template<>
84struct 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
91template<class T, int I>
92struct has_placeholder {
93 BOOST_STATIC_CONSTANT(bool, value = (get_arity<T>::value & I) != 0);
94};
95
96template<int I, int J>
97struct includes_placeholder {
98 BOOST_STATIC_CONSTANT(bool, value = (J & I) != 0);
99};
100
101template<int I, int J>
102struct lacks_placeholder {
103 BOOST_STATIC_CONSTANT(bool, value = ((J & I) == 0));
104};
105
106
107} // namespace lambda
108} // namespace ndnboost
109
110#endif