1 [/==============================================================================
2 Copyright (C) 2001-2011 Joel de Guzman
3 Copyright (C) 2006 Dan Marsden
4 Copyright (C) 2010 Christopher Schmidt
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 ===============================================================================/]
12 Fusion provides a couple of adapters for other sequences such as arrays,
13 `std::pair`, __mpl__ sequences, and `boost::array`. These adapters are
14 written using Fusion's non-intrusive __extension__ mechanism. If you wish
15 to use these sequences with fusion, simply include the necessary files and
16 they will be regarded as first-class, fully conforming fusion sequences.
18 Fusion also provides various schemes to make it easy for the user to adapt
19 various data structures, non-intrusively, as full fledged Fusion sequences.
23 #include <boost/fusion/adapted.hpp>
24 #include <boost/fusion/include/adapted.hpp>
26 Fusion sequences may also be adapted as fully conforming __mpl__ sequences (see
27 __intrinsics__). That way, we can have 2-way adaptation to and from __mpl__ and
28 Fusion. To make Fusion sequences fully conforming __mpl__ sequences, include:
30 #include <boost/fusion/mpl.hpp>
32 If you want bi-directional adaptation to and from __mpl__ and Fusion, simply
35 #include <boost/fusion/include/mpl.hpp>
37 The header includes all the necessary headers.
41 This module provides adapters for arrays. Including the module
42 header makes any array a fully conforming __random_access_sequence__.
46 #include <boost/fusion/adapted/array.hpp>
47 #include <boost/fusion/include/array.hpp>
51 * __random_access_sequence__
57 std::cout << *__begin__(arr) << std::endl;
58 std::cout << *__next__(__begin__(arr)) << std::endl;
59 std::cout << *__advance_c__<2>(__begin__(arr)) << std::endl;
60 std::cout << *__prior__(__end__(arr)) << std::endl;
61 std::cout << __at_c__<2>(arr) << std::endl;
67 This module provides adapters for `std::pair`. Including the module header
68 makes `std::pair` a fully conforming __random_access_sequence__.
72 #include <boost/fusion/adapted/std_pair.hpp>
73 #include <boost/fusion/include/std_pair.hpp>
77 * __random_access_sequence__
81 std::pair<int, std::string> p(123, "Hola!!!");
82 std::cout << __at_c__<0>(p) << std::endl;
83 std::cout << __at_c__<1>(p) << std::endl;
84 std::cout << p << std::endl;
88 __std_pair_doc__, __tr1_tuple_pair__
94 This module provides adapters for `std::tuple`. Including the module header
95 makes `std::tuple` a fully conforming __random_access_sequence__.
97 [important To be fully conforming, compiler should support C++11 Variadic Templates.]
101 #include <boost/fusion/adapted/std_tuple.hpp>
102 #include <boost/fusion/include/std_tuple.hpp>
106 * __random_access_sequence__
110 std::tuple<int, std::string, float> p(123, "Hola!!!", 456.f);
111 std::cout << __at_c__<0>(p) << std::endl;
112 std::cout << __at_c__<1>(p) << std::endl;
113 std::cout << p << std::endl;
121 [section mpl sequence]
123 This module provides adapters for __mpl__ sequences. Including the module
124 header makes all __mpl__ sequences fully conforming fusion sequences.
128 #include <boost/fusion/adapted/mpl.hpp>
129 #include <boost/fusion/include/mpl.hpp>
133 * __forward_sequence__ (If the __mpl__ sequence is a forward sequence.)
134 * __bidirectional_sequence__ (If the __mpl__ sequence is a bidirectional sequence.)
135 * __random_access_sequence__ (If the __mpl__ sequence is a random access sequence.)
139 mpl::vector_c<int, 123, 456> vec_c;
140 fusion::vector2<int, long> v(vec_c);
141 std::cout << __at_c__<0>(v) << std::endl;
142 std::cout << __at_c__<1>(v) << std::endl;
144 v = mpl::vector_c<int, 456, 789>();
145 std::cout << __at_c__<0>(v) << std::endl;
146 std::cout << __at_c__<1>(v) << std::endl;
154 [section boost::array]
156 This module provides adapters for `boost::array`. Including the module
157 header makes `boost::array` a fully conforming __random_access_sequence__.
161 #include <boost/fusion/adapted/boost_array.hpp>
162 #include <boost/fusion/include/boost_array.hpp>
166 * __random_access_sequence__
170 boost::array<int,3> arr = {{1,2,3}};
172 std::cout << *__begin__(arr) << std::endl;
173 std::cout << *__next__(__begin__(arr)) << std::endl;
174 std::cout << *__advance_c__<2>(__begin__(arr)) << std::endl;
175 std::cout << *__prior__(__end__(arr)) << std::endl;
176 std::cout << __at_c__<2>(arr) << std::endl;
180 __boost_array_library__
184 [section boost::tuple]
185 This module provides adapters for `boost::tuple`. Including the module
186 header makes `boost::tuple` a fully conforming __forward_sequence__.
190 #include <boost/fusion/adapted/boost_tuple.hpp>
191 #include <boost/fusion/include/boost_tuple.hpp>
195 * __forward_sequence__
199 boost::tuple<int,std::string> example_tuple(101, "hello");
200 std::cout << *__begin__(example_tuple) << '\n';
201 std::cout << *__next__(__begin__(example_tuple)) << '\n';
205 __boost_tuple_library__
209 [section:adapt_struct BOOST_FUSION_ADAPT_STRUCT]
211 [heading Description]
212 BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
213 necessary boilerplate to make an arbitrary struct a model of
214 __random_access_sequence__.
217 BOOST_FUSION_ADAPT_STRUCT(
225 // Without BOOST_PP_VARIADICS support :
226 BOOST_FUSION_ADAPT_STRUCT(
228 (member_type0, member_name0)
229 (member_type1, member_name1)
236 The above macro generates the necessary code to adapt `struct_name`
237 as a model of __random_access_sequence__.
239 The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
240 pairs declares the type and names of each of the struct members that are part of
243 When member_typeN is omitted or set to auto, the type is
244 infered with Boost.TypeOf.
246 The macro should be used at global scope, and `struct_name` should be the fully
247 namespace qualified name of the struct to be adapted.
251 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
252 #include <boost/fusion/include/adapt_struct.hpp>
254 [heading Example: BOOST_FUSION_ADAPT_STRUCT ]
264 // demo::employee is now a Fusion sequence
265 BOOST_FUSION_ADAPT_STRUCT(
270 // Without BOOST_PP_VARIADICS support :
271 BOOST_FUSION_ADAPT_STRUCT(
279 [section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT]
281 [heading Description]
282 BOOST_FUSION_ADAPT_TPL_STRUCT is a macro that can be used to generate all the
283 necessary boilerplate to make an arbitrary template struct a model of
284 __random_access_sequence__.
287 BOOST_FUSION_ADAPT_TPL_STRUCT(
288 (template_param0)(template_param1)...,
289 (struct_name) (specialization_param0)(specialization_param1)...,
295 // Without BOOST_PP_VARIADICS support :
296 BOOST_FUSION_ADAPT_TPL_STRUCT(
297 (template_param0)(template_param1)...,
298 (struct_name) (specialization_param0)(specialization_param1)...,
299 (member_type0, member_name0)
300 (member_type1, member_name1)
301 (auto, member_name2),
307 The above macro generates the necessary code to adapt `struct_name` or an
308 arbitrary specialization of `struct_name` as a model of
309 __random_access_sequence__.
310 The sequence `(template_param0)(template_param1)...` declares the names of
311 the template type parameters used.
312 The sequence `(specialization_param0)(specialization_param1)...`
313 declares the template parameters of the actual specialization of `struct_name`
314 that is adapted as a fusion sequence.
315 The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
316 pairs declares the type and names of each of the struct members that are part of
319 When member_typeN is omitted or set to auto, the type is
320 infered with Boost.TypeOf.
322 The macro should be used at global scope, and `struct_name` should be the fully
323 namespace qualified name of the struct to be adapted.
327 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
328 #include <boost/fusion/include/adapt_struct.hpp>
333 template<typename Name, typename Age>
338 int employment_timestamp;
342 // Any instantiated demo::employee is now a Fusion sequence
343 BOOST_FUSION_ADAPT_TPL_STRUCT(
345 (demo::employee) (Name)(Age),
348 (auto, employment_timestamp))
350 // Or by infering type completely
351 BOOST_FUSION_ADAPT_TPL_STRUCT(
353 (demo::employee) (Name)(Age),
356 employment_timestamp)
360 [section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED]
362 [heading Description]
363 BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are
364 macros that can be used to generate all the necessary boilerplate to make an
365 arbitrary struct a model of __random_access_sequence__. The given struct is
366 adapted using the given name.
369 BOOST_FUSION_ADAPT_STRUCT_NAMED(
370 struct_name, adapted_name,
377 BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
379 (namespace0)(namespace1)...,
387 // Without BOOST_PP_VARIADICS support :
389 BOOST_FUSION_ADAPT_STRUCT_NAMED(
390 struct_name, adapted_name,
391 (member_type0, member_name0)
392 (member_type1, member_name1)
393 (auto, member_name2),
397 BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
399 (namespace0)(namespace1)...,
401 (member_type0, member_name0)
402 (member_type1, member_name1)
403 (auto, member_name2),
411 The above macros generate the necessary code to adapt `struct_name`
412 as a model of __random_access_sequence__ while using `adapted_name` as the
413 name of the adapted struct.
414 The sequence `(namespace0)(namespace1)...` declares the namespace
415 for `adapted_name`. It yields to a fully qualified name for `adapted_name` of
416 `namespace0::namespace1::... adapted_name`.
417 If an empty namespace sequence is given (that is a macro that expands to
418 nothing), the adapted view is placed in the global namespace.
419 If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the
420 adapted view is placed in the namespace `boost::fusion::adapted`.
421 The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
422 pairs declares the type and names of each of the struct members that are part of
425 When member_typeN is omitted or set to auto, the type is
426 infered with Boost.TypeOf.
428 The macros should be used at global scope, and `struct_name` should be the fully
429 namespace qualified name of the struct to be converted.
433 #include <boost/fusion/adapted/struct/adapt_struct_named.hpp>
434 #include <boost/fusion/include/adapt_struct_named.hpp>
446 // boost::fusion::adapted::adapted_employee is now a Fusion sequence
447 // referring to demo::employee
448 BOOST_FUSION_ADAPT_STRUCT_NAMED(
449 demo::employee, adapted_employee,
453 // Without BOOST_PP_VARIADICS support :
454 BOOST_FUSION_ADAPT_STRUCT_NAMED(
455 demo::employee, adapted_employee,
461 [section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT]
463 [heading Description]
464 BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
465 necessary boilerplate to make an arbitrary struct a model of
466 __random_access_sequence__ and __associative_sequence__.
469 BOOST_FUSION_ADAPT_ASSOC_STRUCT(
471 ([member_type0,] member_name0, key_type0)
472 ([member_type1,] member_name1, key_type1)
478 The above macro generates the necessary code to adapt `struct_name`
479 as a model of __random_access_sequence__ and __associative_sequence__.
480 The sequence of `([member_typeN,] member_nameN, key_typeN)` tuples
481 declares the type, name and key type of each of the struct members
482 that are part of the sequence.
484 When member_typeN is omitted or set to auto, the type is
485 infered with Boost.TypeOf.
487 The macro should be used at global scope, and `struct_name` should be the fully
488 namespace qualified name of the struct to be adapted.
492 #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
493 #include <boost/fusion/include/adapt_assoc_struct.hpp>
511 // demo::employee is now a Fusion sequence.
512 // It is also an associative sequence with
513 // keys keys::name and keys::age present.
514 BOOST_FUSION_ADAPT_ASSOC_STRUCT(
519 // Without BOOST_PP_VARIADICS support :
520 BOOST_FUSION_ADAPT_ASSOC_STRUCT(
522 (auto, name, keys::name),
523 (auto, age, keys::name))
527 [section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT]
529 [heading Description]
530 BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT is a macro that can be used to generate all the
531 necessary boilerplate to make an arbitrary template struct a model of
532 __random_access_sequence__ and __associative_sequence__.
535 BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
536 (template_param0)(template_param1)...,
537 (struct_name) (specialization_param0)(specialization_param1)...,
538 ([member_type0,] member_name0, key_type0)
539 ([member_type1,] member_name1, key_type1)
545 The above macro generates the necessary code to adapt `struct_name` or an
546 arbitrary specialization of `struct_name` as a model of
547 __random_access_sequence__ and __associative_sequence__.
548 The sequence `(template_param0)(template_param1)...` declares the names of
549 the template type parameters used.
550 The sequence `(specialization_param0)(specialization_param1)...`
551 declares the template parameters of the actual specialization of `struct_name`
552 that is adapted as a fusion sequence.
553 The sequence of `([member_typeN,] member_nameN, key_typeN)`
554 tuples declares the type, name and key type of each of the struct members
555 that are part of the sequence.
557 When member_typeN is omitted or set to auto, the type is
558 infered with Boost.TypeOf.
560 The macro should be used at global scope, and `struct_name` should be the fully
561 namespace qualified name of the struct to be adapted.
565 #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
566 #include <boost/fusion/include/adapt_assoc_struct.hpp>
571 template<typename Name, typename Age>
585 // Any instantiated demo::employee is now a Fusion sequence.
586 // It is also an associative sequence with
587 // keys keys::name and keys::age present.
588 BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
590 (demo::employee) (Name)(Age),
594 // Without BOOST_PP_VARIADICS support :
595 BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
597 (demo::employee) (Name)(Age),
598 (Name, name, keys::name)
599 (Age, age, keys::age))
603 [section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED]
605 [heading Description]
606 BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are
607 macros that can be used to generate all the necessary boilerplate to make an
608 arbitrary struct a model of __random_access_sequence__ and
609 __associative_sequence__. The given struct is adapted using the given name.
612 BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
613 struct_name, adapted_name,
614 ([member_type0,] member_name0, key_type0)
615 ([member_type1,] member_name1, key_type1)
619 BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS(
621 (namespace0)(namespace1)...,
623 ([member_type0,] member_name0, key_type0)
624 ([member_type1,] member_name1, key_type1)
630 The above macros generate the necessary code to adapt `struct_name`
631 as a model of __random_access_sequence__ and __associative_sequence__ while
632 using `adapted_name` as the name of the adapted struct.
633 The sequence `(namespace0)(namespace1)...` declares the namespace
634 for `adapted_name`. It yields to a fully qualified name for `adapted_name` of
635 `namespace0::namespace1::... adapted_name`.
636 If an empty namespace sequence is given (that is a macro that expands to
637 nothing), the adapted view is placed in the global namespace.
638 If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_ASSOC_NAMED`), the
639 adapted view is placed in the namespace `boost::fusion::adapted`.
640 The sequence of `(member_typeN, member_nameN, key_typeN)`
641 triples declares the type, name and key type of each of the struct members
642 that are part of the sequence.
644 When member_typeN is omitted or set to auto, the type is
645 infered with Boost.TypeOf.
647 The macros should be used at global scope, and `struct_name` should be the fully
648 namespace qualified name of the struct to be converted.
652 #include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
653 #include <boost/fusion/include/adapt_assoc_struct_named.hpp>
671 // boost::fusion::adapted::adapted_employee is now a Fusion sequence
672 // referring to demo::employee
673 BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
674 demo::employee, adapted_employee,
678 // Without BOOST_PP_VARIADICS support :
679 BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
680 demo::employee, adapted_employee,
681 (auto, name, keys::name)
682 (auto, age, keys::age))
686 [section:adapt_adt BOOST_FUSION_ADAPT_ADT]
688 BOOST_FUSION_ADAPT_ADT is a macro than can be used to generate all the
689 necessary boilerplate to adapt an arbitrary class type as a model of
690 __random_access_sequence__.
694 BOOST_FUSION_ADAPT_ADT(
696 ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0)
697 ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1)
701 [heading Expression Semantics]
703 The above macro generates the necessary code to adapt `type_name`
704 as a model of __random_access_sequence__.
706 [^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N])]
707 quadruples declares the types, const types, get-expressions and set-expressions
708 of the elements that are part of the adapted fusion sequence.
709 [^get_expr['N]] is the expression that is invoked to get the ['N]th element
710 of an instance of `type_name`. This expression may access a variable named
711 `obj` of type `type_name&` or `type_name const&` which represents the underlying
712 instance of `type_name`.
713 [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
714 that [^get_expr['N]] denotes to, when omitted the type is deduced from
715 [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
716 variadic macros auto can be used to avoid repeating the type.
717 [^set_expr['N]] is the expression that is invoked to set the ['N]th element
718 of an instance of `type_name`. This expression may access variables named
719 `obj` of type `type_name&`, which represent the corresponding instance of
720 `type_name`, and `val` of an arbitrary const-qualified reference template type
721 parameter `Val`, which represents the right operand of the assignment
724 The actual return type of fusion's intrinsic sequence access (meta-)functions
725 when in invoked with (an instance of) `type_name` is a proxy type.
726 This type is implicitly convertible to the attribute type via [^get_expr['N]] and
727 forwards assignment to the underlying element via [^set_expr['N]].
728 The value type (that is the type returned by __result_of_value_of__,
729 __result_of_value_at__ and __result_of_value_at_c__) of the ['N]th element
730 is [^attribute_type['N]] with const-qualifier and reference removed.
732 The macro should be used at global scope, and `type_name` should be the fully
733 namespace qualified name of the class type to be adapted.
737 #include <boost/fusion/adapted/adt/adapt_adt.hpp>
738 #include <boost/fusion/include/adapt_adt.hpp>
750 void set_name(std::string const& n)
760 std::string const& get_name()const
772 BOOST_FUSION_ADAPT_ADT(
774 (obj.get_name(), obj.set_name(val))
775 (obj.get_age(), obj.set_age(val)))
778 front(e)="Edward Norton";
780 //Prints 'Edward Norton is 41 years old'
781 std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
785 __adt_attribute_proxy__
789 [section:adapt_tpl_adt BOOST_FUSION_ADAPT_TPL_ADT]
791 BOOST_FUSION_ADAPT_TPL_ADT is a macro than can be used to generate all the
792 necessary boilerplate to adapt an arbitrary template class type as a model of
793 __random_access_sequence__.
797 BOOST_FUSION_ADAPT_TPL_ADT(
798 (template_param0)(template_param1)...,
799 (type_name) (specialization_param0)(specialization_param1)...,
800 ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0)
801 ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1)
805 [heading Expression Semantics]
807 The above macro generates the necessary code to adapt `type_name`
808 or an arbitrary specialization of `type_name`
809 as a model of __random_access_sequence__.
810 The sequence `(template_param0)(template_param1)...` declares the names of
811 the template type parameters used.
812 The sequence `(specialization_param0)(specialization_param1)...`
813 declares the template parameters of the actual specialization of `type_name`
814 that is adapted as a fusion sequence.
816 [^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N])]
817 quadruples declares the types, const types, get-expressions and set-expressions
818 of the elements that are part of the adapted fusion sequence.
819 [^get_expr['N]] is the expression that is invoked to get the ['N]th element
820 of an instance of `type_name`. This expression may access a variable named
821 `obj` of type `type_name&` or `type_name const&` which represents the underlying
822 instance of `type_name`.
823 [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
824 that [^get_expr['N]] denotes to, when omitted the type is deduced from
825 [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
826 variadic macros auto can be used to avoid repeating the type.
827 [^set_expr['N]] is the expression that is invoked to set the ['N]th element
828 of an instance of `type_name`. This expression may access variables named
829 `obj` of type `type_name&`, which represent the corresponding instance of
830 `type_name`, and `val` of an arbitrary const-qualified reference template type
831 parameter `Val`, which represents the right operand of the assignment
834 The actual return type of fusion's intrinsic sequence access (meta-)functions
835 when in invoked with (an instance of) `type_name` is a proxy type.
836 This type is implicitly convertible to the attribute type via [^get_expr['N]] and
837 forwards assignment to the underlying element via [^set_expr['N]].
838 The value type (that is the type returned by __result_of_value_of__,
839 __result_of_value_at__ and __result_of_value_at_c__) of the ['N]th element
840 is [^attribute_type['N]] with const-qualifier and reference removed.
842 The macro should be used at global scope, and `type_name` should be the fully
843 namespace qualified name of the template class type to be adapted.
847 #include <boost/fusion/adapted/adt/adapt_adt.hpp>
848 #include <boost/fusion/include/adapt_adt.hpp>
853 template<typename Name, typename Age>
861 void set_name(Name const& n)
866 void set_age(Age const& a)
871 Name const& get_name()const
876 Age const& get_age()const
883 BOOST_FUSION_ADAPT_TPL_ADT(
885 (demo::employee) (Name)(Age),
886 (Name const&, Name const&, obj.get_name(), obj.set_name(val))
887 (Age const&, Age const&, obj.get_age(), obj.set_age(val)))
889 demo::employee<std::string, int> e;
890 boost::fusion::front(e)="Edward Norton";
891 boost::fusion::back(e)=41;
892 //Prints 'Edward Norton is 41 years old'
893 std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
897 __adt_attribute_proxy__
901 [section:adapt_assoc_adt BOOST_FUSION_ADAPT_ASSOC_ADT]
903 BOOST_FUSION_ADAPT_ASSOC_ADT is a macro than can be used to generate all the
904 necessary boilerplate to adapt an arbitrary class type as a model of
905 __random_access_sequence__ and __associative_sequence__.
909 BOOST_FUSION_ADAPT_ASSOC_ADT(
911 ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0)
912 ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1)
916 [heading Expression Semantics]
918 The above macro generates the necessary code to adapt `type_name`
919 as a model of __random_access_sequence__ and __associative_sequence__.
921 [^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N], key_type['N])]
922 5-tuples declares the types, const types, get-expressions, set-expressions and key types
923 of the elements that are part of the adapted fusion sequence.
924 [^get_expr['N]] is the expression that is invoked to get the ['N]th element
925 of an instance of `type_name`. This expression may access a variable named
926 `obj` of type `type_name&` or `type_name const&` which represents the underlying
927 instance of `type_name`.
928 [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
929 that [^get_expr['N]] denotes to, when omitted the type is deduced from
930 [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
931 variadic macros auto can be used to avoid repeating the type.
932 [^set_expr['N]] is the expression that is invoked to set the ['N]th element
933 of an instance of `type_name`. This expression may access variables named
934 `obj` of type `type_name&`, which represent the corresponding instance of
935 `type_name`, and `val` of an arbitrary const-qualified reference template type
936 parameter `Val`, which represents the right operand of the assignment
939 The actual return type of fusion's intrinsic sequence access (meta-)functions
940 when in invoked with (an instance of) `type_name` is a proxy type.
941 This type is implicitly convertible to the attribute type via [^get_expr['N]] and
942 forwards assignment to the underlying element via [^set_expr['N]].
943 The value type (that is the type returned by __result_of_value_of__, __result_of_value_of_data__,
944 __result_of_value_at__, __result_of_value_at_c__ and __result_of_value_at_key__) of the ['N]th element
945 is [^attribute_type['N]] with const-qualifier and reference removed.
947 The macro should be used at global scope, and `type_name` should be the fully
948 namespace qualified name of the class type to be adapted.
952 #include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp>
953 #include <boost/fusion/include/adapt_assoc_adt.hpp>
965 void set_name(std::string const& n)
975 std::string const& get_name()const
993 BOOST_FUSION_ADAPT_ASSOC_ADT(
995 (obj.get_name(), obj.set_name(val), keys::name)
996 (obj.get_age(), obj.set_age(val), keys::age))
999 at_key<keys::name>(e)="Edward Norton";
1000 at_key<keys::age>(e)=41;
1001 //Prints 'Edward Norton is 41 years old'
1002 std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
1006 __adt_attribute_proxy__
1010 [section:adapt_assoc_tpl_adt BOOST_FUSION_ADAPT_ASSOC_TPL_ADT]
1012 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT is a macro than can be used to generate all the
1013 necessary boilerplate to adapt an arbitrary template class type as a model of
1014 __random_access_sequence__ and __associative_sequence__.
1018 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
1019 (template_param0)(template_param1)...,
1020 (type_name) (specialization_param0)(specialization_param1)...,
1021 ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0)
1022 ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1)
1026 [heading Expression Semantics]
1028 The above macro generates the necessary code to adapt `type_name`
1029 or an arbitrary specialization of `type_name`
1030 as a model of __random_access_sequence__ and __associative_sequence__.
1031 The sequence `(template_param0)(template_param1)...` declares the names of
1032 the template type parameters used.
1033 The sequence `(specialization_param0)(specialization_param1)...`
1034 declares the template parameters of the actual specialization of `type_name`
1035 that is adapted as a fusion sequence.
1037 [^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N], key_type['N])]
1038 5-tuples declares the types, const types, get-expressions, set-expressions and key types
1039 of the elements that are part of the adapted fusion sequence.
1040 [^get_expr['N]] is the expression that is invoked to get the ['N]th element
1041 of an instance of `type_name`. This expression may access a variable named
1042 `obj` of type `type_name&` or `type_name const&` which represents the underlying
1043 instance of `type_name`.
1044 [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
1045 that [^get_expr['N]] denotes to, when omitted the type is deduced from
1046 [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
1047 variadic macros auto can be used to avoid repeating the type.
1048 [^set_expr['N]] is the expression that is invoked to set the ['N]th element
1049 of an instance of `type_name`. This expression may access variables named
1050 `obj` of type `type_name&`, which represent the corresponding instance of
1051 `type_name`, and `val` of an arbitrary const-qualified reference template type
1052 parameter `Val`, which represents the right operand of the assignment
1055 The actual return type of fusion's intrinsic sequence access (meta-)functions
1056 when in invoked with (an instance of) `type_name` is a proxy type.
1057 This type is implicitly convertible to the attribute type via [^get_expr['N]] and
1058 forwards assignment to the underlying element via [^set_expr['N]].
1059 The value type (that is the type returned by __result_of_value_of__, __result_of_value_of_data__,
1060 __result_of_value_at__, __result_of_value_at_c__ and __result_of_value_at_key__) of the ['N]th element
1061 is [^attribute_type['N]] with const-qualifier and reference removed.
1063 The macro should be used at global scope, and `type_name` should be the fully
1064 namespace qualified name of the template class type to be adapted.
1068 #include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp>
1069 #include <boost/fusion/include/adapt_assoc_adt.hpp>
1074 template<typename Name, typename Age>
1082 void set_name(Name const& n)
1087 void set_age(Age const& a)
1092 Name const& get_name()const
1097 Age const& get_age()const
1110 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
1112 (demo::employee) (Name)(Age),
1113 (Name const&, Name const&, obj.get_name(), obj.set_name(val), keys::name)
1114 (Age const&, Age const&, obj.get_age(), obj.set_age(val), keys::age))
1116 demo::employee<std::string, int> e;
1117 at_key<keys::name>(e)="Edward Norton";
1118 at_key<keys::age>(e)=41;
1119 //Prints 'Edward Norton is 41 years old'
1120 std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
1124 __adt_attribute_proxy__
1128 [section:define_struct BOOST_FUSION_DEFINE_STRUCT]
1130 BOOST_FUSION_DEFINE_STRUCT is a macro that can be used to generate all the
1131 necessary boilerplate to define and adapt an arbitrary struct as a model of
1132 __random_access_sequence__.
1136 BOOST_FUSION_DEFINE_STRUCT(
1137 (namespace0)(namespace1)...,
1139 (member_type0, member_name0)
1140 (member_type1, member_name1)
1144 [variablelist Notation
1145 [[`str`] [An instance of `struct_name`]]
1146 [[`e0`...`en`] [Heterogeneous values]]
1147 [[`fs`] [A __forward_sequence__]]
1150 [heading Expression Semantics]
1152 The above macro generates the necessary code that defines and adapts `struct_name`
1153 as a model of __random_access_sequence__.
1154 The sequence `(namespace0)(namespace1)...` declares the namespace
1155 for `struct_name`. It yields to a fully qualified name for `struct_name` of
1156 `namespace0::namespace1::... struct_name`.
1157 If an empty namespace sequence is given (that is a macro that expands to
1158 nothing), the struct is placed in the global namespace.
1159 The sequence of `(member_typeN, member_nameN)`
1160 pairs declares the type and names of each of the struct members that are
1161 part of the sequence.
1163 The macro should be used at global scope.
1164 Semantics of an expression is defined only where it differs from, or is not
1165 defined in __random_access_sequence__.
1168 [[Expression] [Semantics]]
1169 [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]]
1170 [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]]
1171 [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]]
1172 [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
1173 [[`str.member_nameN`] [Access of struct member `member_nameN`]]
1178 #include <boost/fusion/adapted/struct/define_struct.hpp>
1179 #include <boost/fusion/include/define_struct.hpp>
1183 // demo::employee is a Fusion sequence
1184 BOOST_FUSION_DEFINE_STRUCT(
1191 [section:define_tpl_struct BOOST_FUSION_DEFINE_TPL_STRUCT]
1193 [heading Description]
1195 BOOST_FUSION_DEFINE_TPL_STRUCT is a macro that can be used to generate all the
1196 necessary boilerplate to define and adapt an arbitrary template struct as a
1197 model of __random_access_sequence__.
1201 BOOST_FUSION_DEFINE_TPL_STRUCT(
1202 (template_param0)(template_param1)...,
1203 (namespace0)(namespace1)...,
1205 (member_type0, member_name0)
1206 (member_type1, member_name1)
1210 [variablelist Notation
1211 [[`Str`] [An instantiated `struct_name`]]
1212 [[`str`] [An instance of `Str`]]
1213 [[`e0`...`en`] [Heterogeneous values]]
1214 [[`fs`] [A __forward_sequence__]]
1217 [heading Expression Semantics]
1219 The above macro generates the necessary code that defines and adapts `struct_name`
1220 as a model of __random_access_sequence__.
1221 The sequence `(template_param0)(template_param1)...` declares the names of
1222 the template type parameters used.
1223 The sequence `(namespace0)(namespace1)...` declares the namespace
1224 for `struct_name`. It yields to a fully qualified name for `struct_name` of
1225 `namespace0::namespace1::... struct_name`.
1226 If an empty namespace sequence is given (that is a macro that expands to
1227 nothing), the struct is placed in the global namespace.
1228 The sequence of `(member_typeN, member_nameN)`
1229 pairs declares the type and names of each of the struct members that are
1230 part of the sequence.
1232 The macro should be used at global scope.
1233 Semantics of an expression is defined only where it differs from, or is not
1234 defined in __random_access_sequence__.
1237 [[Expression] [Semantics]]
1238 [[`Str()`] [Creates an instance of `Str` with default constructed elements.]]
1239 [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]]
1240 [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]]
1241 [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
1242 [[`str.member_nameN`] [Access of struct member `member_nameN`]]
1247 #include <boost/fusion/adapted/struct/define_struct.hpp>
1248 #include <boost/fusion/include/define_struct.hpp>
1252 // Any instantiated demo::employee is a Fusion sequence
1253 BOOST_FUSION_DEFINE_TPL_STRUCT(
1254 (Name)(Age), (demo), employee,
1260 [section:define_struct_inline BOOST_FUSION_DEFINE_STRUCT_INLINE]
1262 [heading Description]
1264 BOOST_FUSION_DEFINE_STRUCT_INLINE is a macro that can be used to generate all
1265 the necessary boilerplate to define and adapt an arbitrary struct as a model of
1266 __random_access_sequence__. Unlike BOOST_FUSION_DEFINE_STRUCT, it can be used
1267 at class or namespace scope.
1271 BOOST_FUSION_DEFINE_STRUCT_INLINE(
1273 (member_type0, member_name0)
1274 (member_type1, member_name1)
1278 [heading Expression Semantics]
1280 The semantics of BOOST_FUSION_DEFINE_STRUCT_INLINE are identical to those of
1281 BOOST_FUSION_DEFINE_STRUCT, with two differences:
1283 # BOOST_FUSION_DEFINE_STRUCT_INLINE can be used at class or namespace scope, and
1284 thus does not take a namespace list parameter.
1285 # The structure generated by BOOST_FUSION_DEFINE_STRUCT_INLINE has a base class,
1286 and is thus not POD in C++03.
1290 #include <boost/fusion/adapted/struct/define_struct_inline.hpp>
1291 #include <boost/fusion/include/define_struct_inline.hpp>
1295 // enclosing::employee is a Fusion sequence
1298 BOOST_FUSION_DEFINE_STRUCT_INLINE(
1307 [section:define_tpl_struct_inline BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE]
1309 [heading Description]
1311 BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE is a macro that can be used to generate
1312 all the necessary boilerplate to define and adapt an arbitrary template struct
1313 as a model of __random_access_sequence__. Unlike BOOST_FUSION_DEFINE_TPL_STRUCT,
1314 it can be used at class or namespace scope.
1318 BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
1319 (template_param0)(template_param1)...,
1321 (member_type0, member_name0)
1322 (member_type1, member_name1)
1326 [heading Expression Semantics]
1328 The semantics of BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE are identical to those of
1329 BOOST_FUSION_DEFINE_TPL_STRUCT, with two differences:
1331 # BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE can be used at class or namespace scope,
1332 and thus does not take a namespace list parameter.
1333 # The structure generated by BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE has a base
1334 class, and is thus not POD in C++03.
1338 #include <boost/fusion/adapted/struct/define_struct_inline.hpp>
1339 #include <boost/fusion/include/define_struct_inline.hpp>
1343 // Any instantiated enclosing::employee is a Fusion sequence
1346 BOOST_FUSION_DEFINE_TPL_STRUCT(
1347 (Name)(Age), employee,
1354 [section:define_assoc_struct BOOST_FUSION_DEFINE_ASSOC_STRUCT]
1356 [heading Description]
1358 BOOST_FUSION_DEFINE_ASSOC_STRUCT is a macro that can be used to generate all the
1359 necessary boilerplate to define and adapt an arbitrary struct as a model of
1360 __random_access_sequence__ and __associative_sequence__.
1364 BOOST_FUSION_DEFINE_ASSOC_STRUCT(
1365 (namespace0)(namespace1)...,
1367 (member_type0, member_name0, key_type0)
1368 (member_type1, member_name1, key_type1)
1372 [variablelist Notation
1373 [[`str`] [An instance of `struct_name`]]
1374 [[`e0`...`en`] [Heterogeneous values]]
1375 [[`fs`] [A __forward_sequence__]]
1378 [heading Expression Semantics]
1380 The above macro generates the necessary code that defines and adapts `struct_name`
1381 as a model of __random_access_sequence__ and __associative_sequence__.
1382 The sequence `(namespace0)(namespace1)...` declares the namespace
1383 for `struct_name`. It yields to a fully qualified name for `struct_name` of
1384 `namespace0::namespace1::... struct_name`.
1385 If an empty namespace sequence is given (that is a macro that expands to
1386 nothing), the struct is placed in the global namespace.
1387 The sequence of `(member_typeN, member_nameN, key_typeN)`
1388 triples declares the type, name and key type of each of the struct members
1389 that are part of the sequence.
1391 The macro should be used at global scope.
1392 Semantics of an expression is defined only where it differs from, or is not
1393 defined in __random_access_sequence__ and __associative_sequence__.
1396 [[Expression] [Semantics]]
1397 [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]]
1398 [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]]
1399 [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]]
1400 [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
1401 [[`str.member_nameN`] [Access of struct member `member_nameN`]]
1406 #include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
1407 #include <boost/fusion/include/define_assoc_struct.hpp>
1417 // demo::employee is a Fusion sequence
1418 BOOST_FUSION_DEFINE_ASSOC_STRUCT(
1420 (std::string, name, keys::name)
1421 (int, age, keys::age))
1425 [section:define_assoc_tpl_struct BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT]
1427 [heading Description]
1429 BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT is a macro that can be used to generate all
1430 the necessary boilerplate to define and adapt an arbitrary template struct as a
1431 model of __random_access_sequence__ and __associative_sequence__.
1435 BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
1436 (template_param0)(template_param1)...,
1437 (namespace0)(namespace1)...,
1439 (member_type0, member_name0, key_type0)
1440 (member_type1, member_name1, key_type1)
1444 [variablelist Notation
1445 [[`Str`] [An instantiated `struct_name`]]
1446 [[`str`] [An instance of `Str`]]
1447 [[`e0`...`en`] [Heterogeneous values]]
1448 [[`fs`] [A __forward_sequence__]]
1451 [heading Expression Semantics]
1453 The above macro generates the necessary code that defines and adapts
1454 `struct_name` as a model of __random_access_sequence__ and
1455 __associative_sequence__.
1456 The sequence `(template_param0)(template_param1)...` declares the names of
1457 the template type parameters used.
1458 The sequence `(namespace0)(namespace1)...` declares the namespace
1459 for `struct_name`. It yields to a fully qualified name for `struct_name` of
1460 `namespace0::namespace1::... struct_name`.
1461 If an empty namespace sequence is given (that is a macro that expands to
1462 nothing), the struct is placed in the global namespace.
1463 The sequence of `(member_typeN, member_nameN, key_typeN)`
1464 triples declares the type, name and key type of each of the struct members
1465 that are part of the sequence.
1467 The macro should be used at global scope.
1468 Semantics of an expression is defined only where it differs from, or is not
1469 defined in __random_access_sequence__ and __associative_sequence__.
1472 [[Expression] [Semantics]]
1473 [[`Str()`] [Creates an instance of `Str` with default constructed elements.]]
1474 [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]]
1475 [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]]
1476 [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
1477 [[`str.member_nameN`] [Access of struct member `member_nameN`]]
1482 #include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
1483 #include <boost/fusion/include/define_assoc_struct.hpp>
1493 // Any instantiated demo::employee is a Fusion sequence
1494 BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
1495 (Name)(Age), (demo), employee,
1496 (Name, name, keys::name)
1497 (Age, age, keys::age))