blob: 57356083306ae5dab75756f511288703a8b5ec98 [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070013#ifndef NDNBOOST_LAMBDA_ARITY_CODE_HPP
14#define NDNBOOST_LAMBDA_ARITY_CODE_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070015
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049 NDNBOOST_STATIC_CONSTANT(int, value = detail::get_arity_<typename ndnboost::remove_cv<typename ndnboost::remove_reference<T>::type>::type>::value);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070050
51};
52
53namespace detail {
54
55template<class T>
56struct get_arity_ {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070057 NDNBOOST_STATIC_CONSTANT(int, value = 0);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070058};
59
60template<class T>
61struct get_arity_<lambda_functor<T> > {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070062 NDNBOOST_STATIC_CONSTANT(int, value = get_arity<T>::value);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070063};
64
65template<class Action, class Args>
66struct get_arity_<lambda_functor_base<Action, Args> > {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070067 NDNBOOST_STATIC_CONSTANT(int, value = get_tuple_arity<Args>::value);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070068};
69
70template<int I>
71struct get_arity_<placeholder<I> > {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070072 NDNBOOST_STATIC_CONSTANT(int, value = I);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070073};
74
75} // detail
76
77template<class T>
78struct get_tuple_arity {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070079 NDNBOOST_STATIC_CONSTANT(int, value = get_arity<typename T::head_type>::value | get_tuple_arity<typename T::tail_type>::value);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070080};
81
82
83template<>
84struct get_tuple_arity<null_type> {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070085 NDNBOOST_STATIC_CONSTANT(int, value = 0);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070086};
87
88
89 // Does T have placeholder<I> as it's subexpression?
90
91template<class T, int I>
92struct has_placeholder {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093 NDNBOOST_STATIC_CONSTANT(bool, value = (get_arity<T>::value & I) != 0);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070094};
95
96template<int I, int J>
97struct includes_placeholder {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070098 NDNBOOST_STATIC_CONSTANT(bool, value = (J & I) != 0);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070099};
100
101template<int I, int J>
102struct lacks_placeholder {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700103 NDNBOOST_STATIC_CONSTANT(bool, value = ((J & I) == 0));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700104};
105
106
107} // namespace lambda
108} // namespace ndnboost
109
110#endif