blob: c4cef0443a46e3de8bf6c66526e225e2120f2831 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
2// Copyright (C) 2009-2012 Lorenzo Caminiti
3// Distributed under the Boost Software License, Version 1.0
4// (see accompanying file LICENSE_1_0.txt or a copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6// Home at http://www.boost.org/libs/functional/overloaded_function
7
8#if !BOOST_PP_IS_ITERATING
9# ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
10# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
11
12# include <ndnboost/functional/overloaded_function/config.hpp>
13# include <ndnboost/function.hpp>
14# include <ndnboost/preprocessor/iteration/iterate.hpp>
15# include <ndnboost/preprocessor/repetition/enum.hpp>
16# include <ndnboost/preprocessor/cat.hpp>
17# include <ndnboost/preprocessor/comma_if.hpp>
18
19#define BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
20 BOOST_PP_CAT(A, n)
21
22#define BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused) \
23 BOOST_PP_CAT(a, n)
24
25#define BOOST_FUNCTIONAL_DETAIL_arg_tparam(z, n, unused) \
26 typename BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused)
27
28#define BOOST_FUNCTIONAL_DETAIL_arg(z, n, unused) \
29 BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
30 BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused)
31
32#define BOOST_FUNCTIONAL_DETAIL_f \
33 R (BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, \
34 BOOST_FUNCTIONAL_DETAIL_arg_type, ~))
35
36// Do not use namespace ::detail because overloaded_function is already a class.
37namespace ndnboost { namespace overloaded_function_detail {
38
39template<typename F>
40class base {}; // Empty template cannot be used directly (only its spec).
41
42# define BOOST_PP_ITERATION_PARAMS_1 \
43 (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \
44 "ndnboost/functional/overloaded_function/detail/base.hpp"))
45# include BOOST_PP_ITERATE() // Iterate over funciton arity.
46
47} } // namespace
48
49#undef BOOST_FUNCTIONAL_DETAIL_arg_type
50#undef BOOST_FUNCTIONAL_DETAIL_arg_name
51#undef BOOST_FUNCTIONAL_DETAIL_arg_tparam
52#undef BOOST_FUNCTIONAL_DETAIL_arg
53#undef BOOST_FUNCTIONAL_DETAIL_f
54
55# endif // #include guard
56
57#elif BOOST_PP_ITERATION_DEPTH() == 1
58# define BOOST_FUNCTIONAL_DETAIL_arity BOOST_PP_FRAME_ITERATION(1)
59
60template<
61 typename R
62 BOOST_PP_COMMA_IF(BOOST_FUNCTIONAL_DETAIL_arity)
63 BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
64 BOOST_FUNCTIONAL_DETAIL_arg_tparam, ~)
65>
66class base< BOOST_FUNCTIONAL_DETAIL_f > {
67public:
68 /* implicit */ inline base(
69 // This requires specified type to be implicitly convertible to
70 // a ndnboost::function<> functor.
71 ndnboost::function< BOOST_FUNCTIONAL_DETAIL_f > const& f): f_(f)
72 {}
73
74 inline R operator()(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
75 BOOST_FUNCTIONAL_DETAIL_arg, ~)) const {
76 return f_(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
77 BOOST_FUNCTIONAL_DETAIL_arg_name, ~));
78 }
79
80private:
81 ndnboost::function< BOOST_FUNCTIONAL_DETAIL_f > const f_;
82};
83
84# undef BOOST_FUNCTIONAL_DETAIL_arity
85#endif // iteration
86