• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
3 #define BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
4 
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
9 
10 #include <boost/config.hpp>
11 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
12     #define BOOST_CONTRACT_DETAIL_TVARIADIC 0
13 #else
14     #define BOOST_CONTRACT_DETAIL_TVARIADIC 1
15 #endif
16 
17 #if BOOST_CONTRACT_DETAIL_TVARIADIC
18     #include <tuple>
19 
20     /* CODE */
21 
22     namespace boost { namespace contract { namespace detail {
23             namespace tvariadic_ {
24         template<int...> struct indexes {};
25 
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; };
30     } } } } // namespace
31 
32 #else
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>
38 
39     /* PRIVATE */
40 
41     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_(z, n, tuple) \
42         BOOST_PP_CAT(tuple, n)
43 
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))
47 
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) \
52         ;
53 
54     #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_(z, n, tokens) \
55         tokens
56 
57     #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_(z, n, name) \
58         BOOST_PP_CAT(name, n)
59 
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)
64 
65     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_(z, n, name) \
66         typename BOOST_PP_CAT(name, n)
67 #endif
68 
69 /* PUBLIC */
70 
71 #if BOOST_CONTRACT_DETAIL_TVARIADIC
72     #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
73         ,
74 #else
75     #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
76         BOOST_PP_COMMA_IF(arity)
77 #endif
78 
79 #if BOOST_CONTRACT_DETAIL_TVARIADIC
80     #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) /* nothing */
81 #else
82     #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) \
83         BOOST_PP_COMMA_IF(arity)
84 #endif
85 
86 #if BOOST_CONTRACT_DETAIL_TVARIADIC
87     #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) sizeof...(name)
88 #else
89     #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) arity
90 #endif
91 
92 #if BOOST_CONTRACT_DETAIL_TVARIADIC
93     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
94         typename... name
95 #else
96     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
97         BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_, \
98                 name)
99 #endif
100 
101 #if BOOST_CONTRACT_DETAIL_TVARIADIC
102     #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \
103             z, arity, type, qualifier, name) \
104         type qualifier ... name
105 #else
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))
110 #endif
111 
112 #if BOOST_CONTRACT_DETAIL_TVARIADIC
113     #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
114         name...
115 #else
116     #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
117         BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_, name)
118 #endif
119 
120 #if BOOST_CONTRACT_DETAIL_TVARIADIC
121     #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
122         /* nothing */
123 #else
124     #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
125         BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_, \
126                 tokens)
127 #endif
128 
129 // Tuple.
130 
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;
135 #else
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))
140 #endif
141 
142 #if BOOST_CONTRACT_DETAIL_TVARIADIC
143     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \
144             arity, tuple, values) \
145         tuple(values...)
146 #else
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_,\
150                 (tuple, values))
151 #endif
152 
153 #if BOOST_CONTRACT_DETAIL_TVARIADIC
154     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
155         int... indexes
156 #else
157     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
158         /* nothing */
159 #endif
160 
161 #if BOOST_CONTRACT_DETAIL_TVARIADIC
162     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
163         boost::contract::detail::tvariadic_::indexes<_indexes...>
164 #else
165     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
166         /* nothing */
167 #endif
168 
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()
173 #else
174     #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(unused) \
175         /* nothing */
176 #endif
177 
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)...
182 #else
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_,\
186                 tuple)
187 #endif
188 
189 #endif // #include guard
190 
191