1///////////////////////////////////////////////////////////////////////////////
2/// \file template_arity.hpp
3/// Replace all nodes stored by reference by nodes stored by value.
4//
5// Copyright 2011 Eric Niebler. Distributed under the Boost
6// Software License, Version 1.0. (See accompanying file
7// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8//
9// This file is based on a similar one in MPL from Aleksey Gurtovoy.
10
11#ifndef BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07
12#define BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07
13
14// Somewhat indirect definition of BOOST_PROTO_TEMPLATE_ARITY_PARAM is
15// to overcome a shortcoming of the Wave tool used to generate the
16// pre-preprocessed headers.
17#define BOOST_PROTO_TEMPLATE_ARITY_PARAM BOOST_PROTO_TEMPLATE_ARITY_PARAM2
18#define BOOST_PROTO_TEMPLATE_ARITY_PARAM2(param)
19
20#if defined(BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING) || \
21 (defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES))
22
23#include <boost/preprocessor/cat.hpp>
24#include <boost/preprocessor/inc.hpp>
25#include <boost/preprocessor/iteration/iterate.hpp>
26#include <boost/preprocessor/repetition/enum_params.hpp>
27#include <boost/mpl/int.hpp>
28#include <boost/proto/proto_fwd.hpp>
29
30#undef BOOST_PROTO_TEMPLATE_ARITY_PARAM2
31#define BOOST_PROTO_TEMPLATE_ARITY_PARAM2(param) , param
32
33namespace boost { namespace proto { namespace detail
34{
35 sized_type<1>::type template_arity_helper(...);
36
37 // Other overloads generated by the preprocessor
38 #include <boost/proto/detail/template_arity_helper.hpp>
39
40 template<typename F, int N, int Size>
41 struct template_arity_impl2
42 : mpl::int_<Size - 1>
43 {};
44
45 template<typename F, int N = BOOST_PROTO_MAX_ARITY>
46 struct template_arity
47 : template_arity_impl2<
48 F
49 , N
50 , sizeof(detail::template_arity_helper((F **)0, (mpl::int_<N> *)0))
51 >
52 {};
53
54 template<typename F, int N>
55 struct template_arity_impl2<F, N, 1>
56 : template_arity<F, N-1>
57 {};
58
59 template<typename F>
60 struct template_arity_impl2<F, 0, 1>
61 : mpl::int_<-1>
62 {};
63
64}}}
65
66#endif // BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING
67#endif // BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07
68