1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
[/==============================================================================
Copyright (C) 2001-2011 Joel de Guzman
Copyright (C) 2006 Dan Marsden
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
===============================================================================/]
[section Support]
A couple of classes and metafunctions provide basic support for Fusion.
[section is_sequence]
[heading Description]
Metafunction that evaluates to `mpl::true_` if a certain type `T` is a
conforming Fusion __sequence__, `mpl::false_` otherwise. This may be
specialized to accommodate clients which provide Fusion conforming sequences.
[heading Synopsis]
namespace traits
{
template <typename T>
struct is_sequence
{
typedef __unspecified__ type;
};
}
[heading Parameters]
[table
[[Parameter] [Requirement] [Description]]
[[`T`] [Any type] [The type to query.]]
]
[heading Expression Semantics]
typedef traits::is_sequence<T>::type c;
[*Return type]: An __mpl_boolean_constant__.
[*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type
`T` is a conforming Fusion sequence, `mpl::false_` otherwise.
[heading Header]
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/include/is_sequence.hpp>
[heading Example]
BOOST_MPL_ASSERT_NOT(( traits::is_sequence< std::vector<int> > ));
BOOST_MPL_ASSERT_NOT(( is_sequence< int > ));
BOOST_MPL_ASSERT(( traits::is_sequence<__list__<> > ));
BOOST_MPL_ASSERT(( traits::is_sequence<__list__<int> > ));
BOOST_MPL_ASSERT(( traits::is_sequence<__vector__<> > ));
BOOST_MPL_ASSERT(( traits::is_sequence<__vector__<int> > ));
[endsect]
[section is_view]
[heading Description]
Metafunction that evaluates to `mpl::true_` if a certain type `T` is a
conforming Fusion __view__, `mpl::false_` otherwise. A view is a
specialized sequence that does not actually contain data. Views hold
sequences which may be other views. In general, views are held by other
views by value, while non-views are held by other views by reference. `is_view`
may be specialized to accommodate clients providing Fusion conforming views.
[heading Synopsis]
namespace traits
{
template <typename T>
struct is_view
{
typedef __unspecified__ type;
};
}
[heading Parameters]
[table
[[Parameter] [Requirement] [Description]]
[[`T`] [Any type] [The type to query.]]
]
[heading Expression Semantics]
typedef traits::is_view<T>::type c;
[*Return type]: An __mpl_boolean_constant__.
[*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type
`T` is a conforming Fusion view, `mpl::false_` otherwise.
[heading Header]
#include <boost/fusion/support/is_view.hpp>
#include <boost/fusion/include/is_view.hpp>
[heading Example]
BOOST_MPL_ASSERT_NOT(( traits::is_view<std::vector<int> > ));
BOOST_MPL_ASSERT_NOT(( traits::is_view<int> ));
using boost::mpl::_
using boost::is_pointer;
typedef __vector__<int*, char, long*, bool, double> vector_type;
typedef __filter_view__<vector_type, is_pointer<_> > filter_view_type;
BOOST_MPL_ASSERT(( traits::is_view<filter_view_type> ));
[endsect]
[section tag_of]
[heading Description]
All conforming Fusion sequences and iterators have an associated tag type. The
purpose of the tag is to enable __tag_dispatching__ from __intrinsic__
functions to implementations appropriate for the type.
This metafunction may be specialized to accommodate clients providing Fusion
conforming sequences.
[heading Synopsis]
namespace traits
{
template<typename Sequence>
struct tag_of
{
typedef __unspecified__ type;
};
}
[heading Parameters]
[table
[[Parameter] [Requirement] [Description]]
[[`T`] [Any type] [The type to query.]]
]
[heading Expression Semantics]
typedef traits::tag_of<T>::type tag;
[*Return type]: Any type.
[*Semantics]: Returns the tag type associated with `T`.
[heading Header]
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/include/tag_of.hpp>
[heading Example]
typedef traits::tag_of<__list__<> >::type tag1;
typedef traits::tag_of<__list__<int> >::type tag2;
typedef traits::tag_of<__vector__<> >::type tag3;
typedef traits::tag_of<__vector__<int> >::type tag4;
BOOST_MPL_ASSERT((boost::is_same<tag1, tag2>));
BOOST_MPL_ASSERT((boost::is_same<tag3, tag4>));
[endsect]
[section category_of]
[heading Description]
A metafunction that establishes the conceptual classification of a particular
__sequence__ or __iterator__ (see __iterator_concepts__ and
__sequence_concepts__).
[heading Synopsis]
namespace traits
{
template <typename T>
struct category_of
{
typedef __unspecified__ type;
};
}
[heading Parameters]
[table
[[Parameter] [Requirement] [Description]]
[[`T`] [Any type] [The type to query.]]
]
[heading Expression Semantics]
typedef traits::category_of<T>::type category;
[*Return type]:
The return type is derived from one of:
namespace boost { namespace fusion
{
struct incrementable_traversal_tag {};
struct single_pass_traversal_tag
: incrementable_traversal_tag {};
struct forward_traversal_tag
: single_pass_traversal_tag {};
struct bidirectional_traversal_tag
: forward_traversal_tag {};
struct random_access_traversal_tag
: bidirectional_traversal_tag {};
}}
And optionally from:
namespace boost { namespace fusion
{
struct associative_tag {};
}}
[*Semantics]: Establishes the conceptual classification of a particular
__sequence__ or __iterator__.
[heading Header]
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/include/category_of.hpp>
[heading Example]
using boost::is_base_of;
typedef traits::category_of<__list__<> >::type list_category;
typedef traits::category_of<__vector__<> >::type vector_category;
BOOST_MPL_ASSERT(( is_base_of<forward_traversal_tag, list_category> ));
BOOST_MPL_ASSERT(( is_base_of<random_access_traversal_tag, vector_category> ));
[endsect]
[section deduce]
[heading Description]
Metafunction to apply __element_conversion__ to the full argument type.
It removes references to `const`, references to array types are kept, even
if the array is `const`. Reference wrappers are removed (see
__note_ref_wrappers__)[footnote Since C++11, the standard reference wrappers
are also removed.].
[heading Header]
#include <boost/fusion/support/deduce.hpp>
#include <boost/fusion/include/deduce.hpp>
[heading Synopsis]
namespace traits
{
template <typename T>
struct deduce
{
typedef __unspecified__ type;
};
}
[heading Example]
template <typename T>
struct holder
{
typename traits::deduce<T const &>::type element;
holder(T const & a)
: element(a)
{ }
};
template <typename T>
holder<T> make_holder(T const & a)
{
return holder<T>(a);
}
[heading See also]
* __deduce_sequence__
[endsect]
[section deduce_sequence]
[heading Description]
Applies __element_conversion__ to each element in a __forward_sequence__.
The resulting type is a __random_access_sequence__ that provides a converting
constructor accepting the original type as its argument.
[heading Header]
#include <boost/fusion/support/deduce_sequence.hpp>
#include <boost/fusion/include/deduce_sequence.hpp>
[heading Synopsis]
namespace traits
{
template <class Sequence>
struct deduce_sequence
{
typedef __unspecified__ type;
};
}
[heading Example]
template <class Seq>
struct holder
{
typename traits::deduce_sequence<Seq>::type element;
holder(Seq const & a)
: element(a)
{ }
};
template <typename T0, typename T1>
holder< __vector__<T0 const &, T1 const &> >
make_holder(T0 const & a0, T1 const & a1)
{
typedef __vector__<T0 const &, T1 const &> arg_vec_t;
return holder<arg_vec_t>( arg_vec_t(a0,a1) );
}
[heading See also]
* __deduce__
[endsect]
[section pair]
[heading Description]
Fusion `pair` type is a half runtime pair. A half runtime pair is similar
to a __std_pair__, but, unlike __std_pair__, the first type does not have data.
It is used as elements in __map__\ s, for example.
[heading Synopsis]
template <typename First, typename Second>
struct pair;
namespace result_of
{
template <typename Pair>
struct first;
template <typename Pair>
struct second;
template <typename First, typename Second>
struct make_pair;
}
template <typename First, typename Second>
typename result_of::make_pair<First,Second>::type
make_pair(Second const &);
[heading Template parameters]
[table
[[Parameter] [Description]]
[[First] [The first type. This is purely a type. No data is held.]]
[[Second] [The second type. This contains data.]]
]
[variablelist Notation
[[`P`] [Fusion pair type]]
[[`p`, `p2`] [Fusion pairs]]
[[`F`, `S`] [Arbitrary types]]
[[`s`] [Value of type `S`]]
[[`o`] [Output stream]]
[[`i`] [Input stream]]
]
[heading Expression Semantics]
[table
[[Expression] [Semantics]]
[[`P::first_type`] [The type of the first template parameter, `F`, equivalent to
`result_of::first<P>::type`. ]]
[[`P::second_type`] [The type of the second template parameter, `S`, equivalent to
`result_of::second<P>::type`. ]]
[[`P()`] [Default construction.]]
[[`P(s)`] [Construct a pair given value for the second type, `s`.]]
[[`P(p2)`] [Copy constructs a pair from another pair, `p2`.]]
[[`p.second`] [Get the data from `p1`.]]
[[`p = p2`] [Assigns a pair, `p1`, from another pair, `p2`.]]
[[make_pair<F>(s)] [Make a pair given the first type, `F`, and a value for
the second type, `s`. The second type assumes the type of `s`]]
[[`o << p`] [Output `p` to output stream, `o`.]]
[[`i >> p`] [Input `p` from input stream, `i`.]]
[[`p == p2`] [Tests two pairs for equality.]]
[[`p != p2`] [Tests two pairs for inequality.]]
]
[heading Header]
#include <boost/fusion/support/pair.hpp>
#include <boost/fusion/include/pair.hpp>
[heading Example]
pair<int, char> p('X');
std::cout << p << std::endl;
std::cout << make_pair<int>('X') << std::endl;
assert((p == make_pair<int>('X')));
[endsect]
[endsect]
|