2 #ifndef BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
3 #define BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
10 #include <boost/config.hpp>
11 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
12 #define BOOST_CONTRACT_DETAIL_TVARIADIC 0
14 #define BOOST_CONTRACT_DETAIL_TVARIADIC 1
17 #if BOOST_CONTRACT_DETAIL_TVARIADIC
22 namespace boost { namespace contract { namespace detail {
23 namespace tvariadic_ {
24 template<int...> struct indexes {};
26 template<int N, int... I> struct indexes_of :
27 indexes_of<N - 1, N - 1, I...> {};
28 template<int... I> struct indexes_of<0, I...>
29 { typedef indexes<I...> type; };
33 #include <boost/preprocessor/repetition/enum.hpp>
34 #include <boost/preprocessor/repetition/repeat.hpp>
35 #include <boost/preprocessor/tuple/elem.hpp>
36 #include <boost/preprocessor/punctuation/comma_if.hpp>
37 #include <boost/preprocessor/cat.hpp>
41 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_(z, n, tuple) \
42 BOOST_PP_CAT(tuple, n)
44 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_(z, n, tuplevar_values) \
45 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, tuplevar_values), n)( \
46 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, tuplevar_values), n))
48 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_(z, n, type_qualifier_name) \
49 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \
50 BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \
51 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n) \
54 #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_(z, n, tokens) \
57 #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_(z, n, name) \
60 #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_(z, n, type_qualifier_name) \
61 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \
62 BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \
63 BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n)
65 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_(z, n, name) \
66 typename BOOST_PP_CAT(name, n)
71 #if BOOST_CONTRACT_DETAIL_TVARIADIC
72 #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
75 #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
76 BOOST_PP_COMMA_IF(arity)
79 #if BOOST_CONTRACT_DETAIL_TVARIADIC
80 #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) /* nothing */
82 #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) \
83 BOOST_PP_COMMA_IF(arity)
86 #if BOOST_CONTRACT_DETAIL_TVARIADIC
87 #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) sizeof...(name)
89 #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) arity
92 #if BOOST_CONTRACT_DETAIL_TVARIADIC
93 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
96 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
97 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_, \
101 #if BOOST_CONTRACT_DETAIL_TVARIADIC
102 #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \
103 z, arity, type, qualifier, name) \
104 type qualifier ... name
106 #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \
107 z, arity, type, qualifier, name) \
108 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_, \
109 (type, qualifier, name))
112 #if BOOST_CONTRACT_DETAIL_TVARIADIC
113 #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
116 #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
117 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_, name)
120 #if BOOST_CONTRACT_DETAIL_TVARIADIC
121 #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
124 #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
125 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_, \
131 #if BOOST_CONTRACT_DETAIL_TVARIADIC
132 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \
133 z, arity, type, qualifier, name) \
134 std::tuple<type qualifier ...> name;
136 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \
137 z, arity, type, qualifier, name) \
138 BOOST_PP_REPEAT_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_, \
139 (type, qualifier, name))
142 #if BOOST_CONTRACT_DETAIL_TVARIADIC
143 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \
144 arity, tuple, values) \
147 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \
148 arity, tuple, values) \
149 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_,\
153 #if BOOST_CONTRACT_DETAIL_TVARIADIC
154 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
157 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
161 #if BOOST_CONTRACT_DETAIL_TVARIADIC
162 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
163 boost::contract::detail::tvariadic_::indexes<_indexes...>
165 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
169 #if BOOST_CONTRACT_DETAIL_TVARIADIC
170 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(tuple_type) \
171 typename boost::contract::detail::tvariadic_::indexes_of< \
172 sizeof...(tuple_type)>::type()
174 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(unused) \
178 #if BOOST_CONTRACT_DETAIL_TVARIADIC
179 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \
180 z, arity, indexes, tuple) \
181 std::get<indexes>(tuple)...
183 #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \
184 z, arity, indexes, tuple) \
185 BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_,\
189 #endif // #include guard