3 #ifndef __CDS_OPT_MAKE_OPTIONS_VAR_H
4 #define __CDS_OPT_MAKE_OPTIONS_VAR_H
6 #ifndef __CDS_OPT_OPTIONS_H
7 # error <cds/opt/options.h> must be included instead of <cds/opt/make_options_var.h>
10 #define CDS_DECL_OPTIONS1 typename... Options
11 #define CDS_DECL_OPTIONS2 typename... Options
12 #define CDS_DECL_OPTIONS3 typename... Options
13 #define CDS_DECL_OPTIONS4 typename... Options
14 #define CDS_DECL_OPTIONS5 typename... Options
15 #define CDS_DECL_OPTIONS6 typename... Options
16 #define CDS_DECL_OPTIONS7 typename... Options
17 #define CDS_DECL_OPTIONS8 typename... Options
18 #define CDS_DECL_OPTIONS9 typename... Options
19 #define CDS_DECL_OPTIONS10 typename... Options
20 #define CDS_DECL_OPTIONS11 typename... Options
21 #define CDS_DECL_OPTIONS12 typename... Options
22 #define CDS_DECL_OPTIONS13 typename... Options
23 #define CDS_DECL_OPTIONS14 typename... Options
24 #define CDS_DECL_OPTIONS15 typename... Options
25 #define CDS_DECL_OPTIONS16 typename... Options
27 #define CDS_DECL_OPTIONS typename... Options
30 #define CDS_DECL_OTHER_OPTIONS1 typename... Options2
31 #define CDS_DECL_OTHER_OPTIONS2 typename... Options2
32 #define CDS_DECL_OTHER_OPTIONS3 typename... Options2
33 #define CDS_DECL_OTHER_OPTIONS4 typename... Options2
34 #define CDS_DECL_OTHER_OPTIONS5 typename... Options2
35 #define CDS_DECL_OTHER_OPTIONS6 typename... Options2
36 #define CDS_DECL_OTHER_OPTIONS7 typename... Options2
37 #define CDS_DECL_OTHER_OPTIONS8 typename... Options2
38 #define CDS_DECL_OTHER_OPTIONS9 typename... Options2
39 #define CDS_DECL_OTHER_OPTIONS10 typename... Options2
40 #define CDS_DECL_OTHER_OPTIONS11 typename... Options2
41 #define CDS_DECL_OTHER_OPTIONS12 typename... Options2
42 #define CDS_DECL_OTHER_OPTIONS13 typename... Options2
43 #define CDS_DECL_OTHER_OPTIONS14 typename... Options2
44 #define CDS_DECL_OTHER_OPTIONS15 typename... Options2
45 #define CDS_DECL_OTHER_OPTIONS16 typename... Options2
47 // for template specializations
48 #define CDS_SPEC_OPTIONS1 typename... Options
49 #define CDS_SPEC_OPTIONS2 typename... Options
50 #define CDS_SPEC_OPTIONS3 typename... Options
51 #define CDS_SPEC_OPTIONS4 typename... Options
52 #define CDS_SPEC_OPTIONS5 typename... Options
53 #define CDS_SPEC_OPTIONS6 typename... Options
54 #define CDS_SPEC_OPTIONS7 typename... Options
55 #define CDS_SPEC_OPTIONS8 typename... Options
56 #define CDS_SPEC_OPTIONS9 typename... Options
57 #define CDS_SPEC_OPTIONS10 typename... Options
58 #define CDS_SPEC_OPTIONS11 typename... Options
59 #define CDS_SPEC_OPTIONS12 typename... Options
60 #define CDS_SPEC_OPTIONS13 typename... Options
61 #define CDS_SPEC_OPTIONS14 typename... Options
62 #define CDS_SPEC_OPTIONS15 typename... Options
63 #define CDS_SPEC_OPTIONS16 typename... Options
65 #define CDS_SPEC_OPTIONS typename... Options
67 #define CDS_OPTIONS1 Options...
68 #define CDS_OPTIONS2 Options...
69 #define CDS_OPTIONS3 Options...
70 #define CDS_OPTIONS4 Options...
71 #define CDS_OPTIONS5 Options...
72 #define CDS_OPTIONS6 Options...
73 #define CDS_OPTIONS7 Options...
74 #define CDS_OPTIONS8 Options...
75 #define CDS_OPTIONS9 Options...
76 #define CDS_OPTIONS10 Options...
77 #define CDS_OPTIONS11 Options...
78 #define CDS_OPTIONS12 Options...
79 #define CDS_OPTIONS13 Options...
80 #define CDS_OPTIONS14 Options...
81 #define CDS_OPTIONS15 Options...
82 #define CDS_OPTIONS16 Options...
83 //#define CDS_OPTIONS17 Options...
84 //#define CDS_OPTIONS18 Options...
85 //#define CDS_OPTIONS19 Options...
86 //#define CDS_OPTIONS20 Options...
88 #define CDS_OPTIONS Options...
90 #define CDS_OTHER_OPTIONS1 Options2...
91 #define CDS_OTHER_OPTIONS2 Options2...
92 #define CDS_OTHER_OPTIONS3 Options2...
93 #define CDS_OTHER_OPTIONS4 Options2...
94 #define CDS_OTHER_OPTIONS5 Options2...
95 #define CDS_OTHER_OPTIONS6 Options2...
96 #define CDS_OTHER_OPTIONS7 Options2...
97 #define CDS_OTHER_OPTIONS8 Options2...
98 #define CDS_OTHER_OPTIONS9 Options2...
99 #define CDS_OTHER_OPTIONS10 Options2...
100 #define CDS_OTHER_OPTIONS11 Options2...
101 #define CDS_OTHER_OPTIONS12 Options2...
102 #define CDS_OTHER_OPTIONS13 Options2...
103 #define CDS_OTHER_OPTIONS14 Options2...
104 #define CDS_OTHER_OPTIONS15 Options2...
105 #define CDS_OTHER_OPTIONS16 Options2...
107 namespace cds { namespace opt {
111 template <typename OptionList, typename Option>
114 // Use "pack" member template to pack options
115 typedef typename Option::template pack<OptionList> type;
118 template <typename ...T> class typelist;
120 template <typename Typelist> struct typelist_head;
121 template <typename Head, typename ...Tail>
122 struct typelist_head< typelist<Head, Tail...> > {
125 template <typename Head>
126 struct typelist_head< typelist<Head> > {
130 template <typename Typelist> struct typelist_tail;
131 template <typename Head, typename ...Tail>
132 struct typelist_tail< typelist<Head, Tail...> > {
133 typedef typelist<Tail...> type;
135 template <typename Head>
136 struct typelist_tail< typelist<Head> > {
137 typedef typelist<> type;
140 template <typename OptionList, typename Typelist>
141 struct make_options_impl {
142 typedef typename make_options_impl<
145 typename typelist_head< Typelist >::type
147 typename typelist_tail<Typelist>::type
151 template <typename OptionList>
152 struct make_options_impl<OptionList, typelist<> > {
153 typedef OptionList type;
155 } // namespace details
158 /// make_options metafunction
159 /** @headerfile cds/opt/options.h
161 The metafunction converts option list \p Options to traits structure.
162 The result of metafunction is \p type.
164 Template parameter \p OptionList is default option set (default traits).
165 \p Options is option list.
167 template <typename OptionList, typename... Options>
168 struct make_options {
169 #ifdef CDS_DOXYGEN_INVOKED
170 typedef implementation_defined type ; ///< Result of the metafunction
172 typedef typename details::make_options_impl< OptionList, details::typelist<Options...> >::type type;
177 // *****************************************************************
178 // find_type_traits metafunction
179 // *****************************************************************
183 template <typename... Options>
184 struct find_type_traits_option;
187 struct find_type_traits_option<> {
188 typedef cds::opt::none type;
191 template <typename Any>
192 struct find_type_traits_option< Any > {
193 typedef cds::opt::none type;
196 template <typename Any>
197 struct find_type_traits_option< cds::opt::type_traits< Any > > {
201 template <typename Any, typename... Options>
202 struct find_type_traits_option< cds::opt::type_traits< Any >, Options... > {
206 template <typename Any, typename... Options>
207 struct find_type_traits_option< Any, Options... > {
208 typedef typename find_type_traits_option< Options... >::type type;
210 } // namespace details
213 /// Metafunction to find opt::type_traits option in \p Options list
214 /** @headerfile cds/opt/options.h
216 If \p Options contains opt::type_traits option then it is the metafunction result.
217 Otherwise the result is \p DefaultOptons.
219 template <typename DefaultOptions, typename... Options>
220 struct find_type_traits {
221 typedef typename select_default< typename details::find_type_traits_option<Options...>::type, DefaultOptions>::type type ; ///< Metafunction result
225 // *****************************************************************
226 // find_option metafunction
227 // *****************************************************************
231 template <typename What, typename... Options>
237 template <typename A, typename B>
238 struct compare_option
240 typedef compare_fail type;
243 template <template <typename> class Opt, typename A, typename B>
244 struct compare_option< Opt<A>, Opt<B> >
246 typedef compare_ok type;
249 // Specializations for integral type of option
250 #define _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION( _type ) template <template <_type> class What, _type A, _type B> \
251 struct compare_option< What<A>, What<B> > { typedef compare_ok type ; };
253 // For user-defined enum types
254 #define CDS_DECLARE_FIND_OPTION_INTEGRAL_SPECIALIZATION( _type ) namespace cds { namespace opt { namespace details { _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(_type ) }}}
256 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(bool)
257 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(char)
258 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(unsigned char)
259 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(signed char)
260 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(short int)
261 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(unsigned short int)
262 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(int)
263 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(unsigned int)
264 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(long)
265 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(unsigned long)
266 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(long long)
267 _CDS_FIND_OPTION_INTEGRAL_SPECIALIZATION(unsigned long long)
270 template <typename CompResult, typename Ok, typename Fail>
276 template <typename Ok, typename Fail>
277 struct select_option< compare_ok, Ok, Fail >
282 template <typename What>
283 struct find_option< What > {
287 template <typename What, typename Opt>
288 struct find_option< What, Opt > {
289 typedef typename select_option<
290 typename compare_option< What, Opt >::type
296 template <typename What, typename Opt, typename... Options>
297 struct find_option< What, Opt, Options... > {
298 typedef typename select_option<
299 typename compare_option< What, Opt >::type
301 ,typename find_option< What, Options... >::type
304 } // namespace details
307 /// Metafunction to find \p What option in \p Options list
308 /** @headerfile cds/opt/options.h
310 If \p Options contains \p What< Val > option for any \p Val then the result is \p What< Val >
311 Otherwise the result is \p What.
315 #include <cds/opt/options.h>
316 namespace co = cds::opt;
322 // Find option co::tag.
324 // res1 is co::tag< tag_a >
325 typedef co::find_option< co::tag< default_tag >, co::gc< cds::gc::HP >, co::tag< tag_a > >::type res1;
327 // res2 is default co::tag< default_tag >
328 typedef co::find_option< co::tag< default_tag >, co::less< x >, co::hash< H > >::type res2;
330 // Multiple option co::tag. The first option is selected
331 // res3 is default co::tag< tag_a >
332 typedef co::find_option< co::tag< default_tag >, co::tag< tag_a >, co::tag< tag_b > >::type res3;
336 template <typename What, typename... Options>
338 typedef typename details::find_option<What, Options...>::type type ; ///< Metafunction result
342 // *****************************************************************
343 // select metafunction
344 // *****************************************************************
349 template <typename What, typename... Pairs>
352 template <typename What, typename Value>
353 struct select< What, What, Value>
358 template <typename What, typename Tag, typename Value>
359 struct select<What, Tag, Value>
364 template <typename What, typename Value, typename... Pairs>
365 struct select< What, What, Value, Pairs...>
370 template <typename What, typename Tag, typename Value, typename... Pairs>
371 struct select< What, Tag, Value, Pairs...>
373 typedef typename select<What, Pairs...>::type type;
375 } // namespace details
378 /// Select option metafunction
379 /** @headerfile cds/opt/options.h
383 select <What, T1, R1, T2, R2, ... Tn, Rn> ::=
384 if What == T1 then return R1
385 if What == T2 then return R2
387 if What == Tn then return Rn
391 template <typename What, typename... Pairs>
393 typedef typename details::select< What, Pairs...>::type type ; ///< Metafunction result
396 }} // namespace cds::opt
398 #endif // #ifndef __CDS_OPT_MAKE_OPTIONS_STD_H