File: adapted.qbk

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (247 lines) | stat: -rw-r--r-- 6,931 bytes parent folder | download
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
[/==============================================================================
    Copyright (C) 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger

    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 Adapted]

Fusion provides a couple of adapters for other sequences such as
`std::pair`, __mpl__ sequences, and `boost::array`. These adapters are
written using Fusion's non-intrusive __extension__ mechanism. If you wish
to use these sequences with fusion, simply include the necessary files and
they will be regarded as first-class, fully conforming fusion sequences
[footnote Fusion sequences may also be adapted as fully conforming __mpl__
sequences (see __intrinsics__). That way, we can have 2-way adaptation to
and from __mpl__ and Fusion].

Fusion also provides various schemes to make it easy for the user to adapt
various data structures, non-intrusively, as full fledged Fusion sequences.

[heading Header]

    #include <boost/fusion/adapted.hpp>
    #include <boost/fusion/include/adapted.hpp>

[section std::pair]

This module provides adapters for `std::pair`. Including the module header
makes `std::pair` a fully conforming __random_access_sequence__.

[heading Header]

    #include <boost/fusion/adapted/std_pair.hpp>
    #include <boost/fusion/include/std_pair.hpp>

[heading Model of]

* __random_access_sequence__

[heading Example]

    std::pair<int, std::string> p(123, "Hola!!!");
    std::cout << __at_c__<0>(p) << std::endl;
    std::cout << __at_c__<1>(p) << std::endl;
    std::cout << p << std::endl;

[heading See also]

__std_pair_doc__, __tr1_tuple_pair__

[endsect]

[section mpl sequence]

This module provides adapters for __mpl__ sequences. Including the module
header makes all __mpl__ sequences fully conforming fusion sequences.

[heading Header]

    #include <boost/fusion/adapted/mpl.hpp>
    #include <boost/fusion/include/mpl.hpp>

[heading Model of]

* __forward_sequence__ (If the __mpl__ sequence is a forward sequence.)
* __bidirectional_sequence__ (If the __mpl__ sequence is a bidirectional sequence.)
* __random_access_sequence__ (If the __mpl__ sequence is a random access sequence.)

[heading Example]

    mpl::vector_c<int, 123, 456> vec_c;
    fusion::vector2<int, long> v(vec_c);
    std::cout << __at_c__<0>(v) << std::endl;
    std::cout << __at_c__<1>(v) << std::endl;

    v = mpl::vector_c<int, 456, 789>();
    std::cout << __at_c__<0>(v) << std::endl;
    std::cout << __at_c__<1>(v) << std::endl;

[heading See also]

__mpl__

[endsect]

[section boost::array]

This module provides adapters for `boost::array`. Including the module
header makes `boost::array` a fully conforming __random_access_sequence__.

[heading Header]

    #include <boost/fusion/adapted/array.hpp>
    #include <boost/fusion/include/array.hpp>

[heading Model of]

* __random_access_sequence__

[heading Example]

    boost::array<int,3> arr = {{1,2,3}};

    std::cout << *__begin__(arr) << std::endl;
    std::cout << *__next__(__begin__(arr)) << std::endl;
    std::cout << *__advance_c__<2>(__begin__(arr)) << std::endl;
    std::cout << *__prior__(__end__(arr)) << std::endl;
    std::cout << __at_c__<2>(arr) << std::endl;

[heading See also]

__boost_array_library__

[endsect]

[section boost::tuple]
This module provides adapters for `boost::tuple`. Including the module
header makes `boost::tuple` a fully conforming __forward_sequence__.

[heading Header]

    #include <boost/fusion/adapted/boost_tuple.hpp>
    #include <boost/fusion/include/boost_tuple.hpp>

[heading Model of]

* __forward_sequence__

[heading Example]

    boost::tuple<int,std::string> example_tuple(101, "hello");
    std::cout << *boost::fusion::begin(example_tuple) << '\n';
    std::cout << *boost::fusion::next(boost::fusion::begin(example_tuple)) << '\n';

[heading See also]

__boost_tuple_library__

[endsect]

[section:adapt_struct BOOST_FUSION_ADAPT_STRUCT]

[heading Description]
BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
necessary boilerplate to make an arbitrary struct into a __random_access_sequence__.

[heading Synopsis]
    BOOST_FUSION_ADAPT_STRUCT(
        struct_name
        (member_type0, member_name0)
        (member_type1, member_name1)
        ...
        )

[heading Semantics]

The above macro generates the necessary code to adapt `struct_name`
as a model of __random_access_sequence__. The sequence of `(member_typeN, member_nameN)`
pairs declare the type and names of each of the struct members that will be
part of the sequence.

The macro should be used at global scope, and `struct_name` should be the fully
namespace qualified name of the struct to be converted.

[heading Header]

    #include <boost/fusion/adapted/struct/adapt_struct.hpp>
    #include <boost/fusion/include/adapt_struct.hpp>

[heading Example]
    namespace demo
    {
        struct employee
        {
            std::string name;
            int age;
        };
    }

    // demo::employee is now a Fusion sequence
    BOOST_FUSION_ADAPT_STRUCT(
        demo::employee
        (std::string, name)
        (int, age))

[endsect]

[section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT]

[heading Description]
BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
necessary boilerplate to make an arbitrary struct into a model of  __random_access_sequence__
and __associative_sequence__.

[heading Synopsis]
    BOOST_FUSION_ADAPT_ASSOC_STRUCT(
        struct_name
        (member_type0, member_name0, key_type0)
        (member_type1, member_name1, key_type1)
        ...
        )

[heading Semantics]

The above macro generates the necessary code to adapt `struct_name`
as a model of __random_access_sequence__ and __associative_sequence__.
The sequence of `(member_typeN, member_nameN, key_typeN)`
triples declare the type, name and key type of each of the struct members
that will be part of the sequence.

The macro should be used at global scope, and `struct_name` should be the fully
namespace qualified name of the struct to be converted.

[heading Header]

    #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
    #include <boost/fusion/include/adapt_assoc_struct.hpp>

[heading Example]
    namespace demo
    {
        struct employee
        {
            std::string name;
            int age;
        };
    }

    namespace keys
    {
        struct name;
        struct age;
    }

    // demo::employee is now a Fusion sequence
    // It is also an associative sequence with
    // keys keys::name and keys::age present.
    BOOST_FUSION_ADAPT_ASSOC_STRUCT(
        demo::employee
        (std::string, name, keys::name)
        (int, age, keys::age))


[endsect]

[endsect]