[/============================================================================== Copyright (C) 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger Copyright (C) 2010 Christopher Schmidt 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 arrays, `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. 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 #include 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. To make Fusion sequences fully conforming __mpl__ sequences, include: #include If you want bi-directional adaptation to and from __mpl__ and Fusion, simply include: #include The header includes all the necessary headers. [section:array Array] This module provides adapters for arrays. Including the module header makes any array a fully conforming __random_access_sequence__. [heading Header] #include #include [heading Model of] * __random_access_sequence__ [heading Example] int arr[3] = {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; [endsect] [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 #include [heading Model of] * __random_access_sequence__ [heading Example] std::pair 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 #include [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 vec_c; fusion::vector2 v(vec_c); std::cout << __at_c__<0>(v) << std::endl; std::cout << __at_c__<1>(v) << std::endl; v = mpl::vector_c(); 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 #include [heading Model of] * __random_access_sequence__ [heading Example] boost::array 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 #include [heading Model of] * __forward_sequence__ [heading Example] boost::tuple 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 a model of __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 declares the type and names of each of the struct members that are 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 adapted. [heading Header] #include #include [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_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT] [heading Description] BOOST_FUSION_ADAPT_TPL_STRUCT is a macro that can be used to generate all the necessary boilerplate to make an arbitrary template struct a model of __random_access_sequence__. [heading Synopsis] BOOST_FUSION_ADAPT_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., (member_type0, member_name0) (member_type1, member_name1) ... ) [heading Semantics] The above macro generates the necessary code to adapt `struct_name` or an arbitrary specialization of `struct_name` as a model of __random_access_sequence__. The sequence `(template_param0)(template_param1)...` declares the names of the template type parameters used. The sequence `(specialization_param0)(specialization_param1)...` declares the template parameters of the actual specialization of `struct_name` that is adapted as a fusion sequence. The sequence of `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are 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 adapted. [heading Header] #include #include [heading Example] namespace demo { template struct employee { Name name; Age age; }; } // Any instantiated demo::employee is now a Fusion sequence BOOST_FUSION_ADAPT_TPL_STRUCT( (Name)(Age), (demo::employee) (Name)(Age), (Name, name) (Age, age)) [endsect] [section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are macros that can be used to generate all the necessary boilerplate to make an arbitrary struct a model of __random_access_sequence__. The given struct is adapted using the given name. [heading Synopsis] BOOST_FUSION_ADAPT_STRUCT_NAMED( struct_name, adapted_name, (member_type0, member_name0) (member_type1, member_name1) ... ) BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., adapted_name, (member_type0, member_name0) (member_type1, member_name1) ... ) [heading Semantics] The above macros generate the necessary code to adapt `struct_name` as a model of __random_access_sequence__ while using `adapted_name` as the name of the adapted struct. The sequence `(namespace0)(namespace1)...` declares the namespace for `adapted_name`. It yields to a fully qualified name for `adapted_name` of `namespace0::namespace1::... adapted_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the adapted view is placed in the global namespace. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the adapted view is placed in the namespace `boost::fusion::adapted`. The sequence of `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are part of the sequence. The macros 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 #include [heading Example] namespace demo { struct employee { std::string name; int age; }; } // boost::fusion::adapted::adapted_employee is now a Fusion sequence // referring to demo::employee BOOST_FUSION_ADAPT_STRUCT_NAMED( demo::employee, adapted_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 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 declares the type, name and key type of each of the struct members that are 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 adapted. [heading Header] #include #include [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] [section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT] [heading Description] BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT is a macro that can be used to generate all the necessary boilerplate to make an arbitrary template struct a model of __random_access_sequence__ and __associative_sequence__. [heading Synopsis] BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., (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` or an arbitrary specialization of `struct_name` as a model of __random_access_sequence__ and __associative_sequence__. The sequence `(template_param0)(template_param1)...` declares the names of the template type parameters used. The sequence `(specialization_param0)(specialization_param1)...` declares the template parameters of the actual specialization of `struct_name` that is adapted as a fusion sequence. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are 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 adapted. [heading Header] #include #include [heading Example] namespace demo { template struct employee { Name name; Age age; }; } namespace keys { struct name; struct age; } // Any instantiated 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_TPL_STRUCT( (Name)(Age), (demo::employee) (Name)(Age), (Name, name, keys::name) (Age, age, keys::age)) [endsect] [section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are macros that can be used to generate all the necessary boilerplate to make an arbitrary struct a model of __random_access_sequence__ and __associative_sequence__. The given struct is adapted using the given name. [heading Synopsis] BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( struct_name, adapted_name, (member_type0, member_name0, key_type0) (member_type1, member_name1, key_type1) ... ) BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., adapted_name, (member_type0, member_name0, key_type0) (member_type1, member_name1, key_type1) ... ) [heading Semantics] The above macros generate the necessary code to adapt `struct_name` as a model of __random_access_sequence__ and __associative_sequence__ while using `adapted_name` as the name of the adapted struct. The sequence `(namespace0)(namespace1)...` declares the namespace for `adapted_name`. It yields to a fully qualified name for `adapted_name` of `namespace0::namespace1::... adapted_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the adapted view is placed in the global namespace. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_ASSOC_NAMED`), the adapted view is placed in the namespace `boost::fusion::adapted`. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are part of the sequence. The macros 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 #include [heading Example] namespace demo { struct employee { std::string name; int age; }; } namespace keys { struct name; struct age; } // boost::fusion::adapted::adapted_employee is now a Fusion sequence // referring to demo::employee BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( demo::employee, adapted_employee, (std::string, name, keys::name) (int, age, keys::age)) [endsect] [section:define_struct BOOST_FUSION_DEFINE_STRUCT] [heading Description] BOOST_FUSION_DEFINE_STRUCT is a macro that can be used to generate all the necessary boilerplate to define and adapt an arbitrary struct as a model of __random_access_sequence__. [heading Synopsis] BOOST_FUSION_DEFINE_STRUCT( (namespace0)(namespace1)..., struct_name, (member_type0, member_name0) (member_type1, member_name1) ... ) [variablelist Notation [[`str`] [An instance of `struct_name`]] [[`e0`...`en`] [Heterogeneous values]] [[`fs`] [A __forward_sequence__]] ] [heading Expression Semantics] The above macro generates the necessary code that defines and adapts `struct_name` as a model of __random_access_sequence__. The sequence `(namespace0)(namespace1)...` declares the namespace for `struct_name`. It yields to a fully qualified name for `struct_name` of `namespace0::namespace1::... struct_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the struct is placed in the global namespace. The sequence of `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are part of the sequence. The macro should be used at global scope. Semantics of an expression is defined only where it differs from, or is not defined in __random_access_sequence__. [table [[Expression] [Semantics]] [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]] [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]] [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]] [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]] [[`str.member_nameN`] [Access of struct member `member_nameN`]] ] [heading Header] #include #include [heading Example] // demo::employee is a Fusion sequence BOOST_FUSION_DEFINE_STRUCT( (demo), employee, (std::string, name) (int, age)) [endsect] [section:define_tpl_struct BOOST_FUSION_DEFINE_TPL_STRUCT] [heading Description] BOOST_FUSION_DEFINE_TPL_STRUCT is a macro that can be used to generate all the necessary boilerplate to define and adapt an arbitrary template struct as a model of __random_access_sequence__. [heading Synopsis] BOOST_FUSION_DEFINE_TPL_STRUCT( (template_param0)(template_param1)..., (namespace0)(namespace1)..., struct_name, (member_type0, member_name0) (member_type1, member_name1) ... ) [variablelist Notation [[`Str`] [An instantiated `struct_name`]] [[`str`] [An instance of `Str`]] [[`e0`...`en`] [Heterogeneous values]] [[`fs`] [A __forward_sequence__]] ] [heading Expression Semantics] The above macro generates the necessary code that defines and adapts `struct_name` as a model of __random_access_sequence__. The sequence `(template_param0)(template_param1)...` declares the names of the template type parameters used. The sequence `(namespace0)(namespace1)...` declares the namespace for `struct_name`. It yields to a fully qualified name for `struct_name` of `namespace0::namespace1::... struct_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the struct is placed in the global namespace. The sequence of `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are part of the sequence. The macro should be used at global scope. Semantics of an expression is defined only where it differs from, or is not defined in __random_access_sequence__. [table [[Expression] [Semantics]] [[`Str()`] [Creates an instance of `Str` with default constructed elements.]] [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]] [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]] [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]] [[`str.member_nameN`] [Access of struct member `member_nameN`]] ] [heading Header] #include #include [heading Example] // Any instantiated demo::employee is a Fusion sequence BOOST_FUSION_DEFINE_TPL_STRUCT( (Name)(Age), (demo), employee, (Name, name) (Age, age)) [endsect] [section:define_assoc_struct BOOST_FUSION_DEFINE_ASSOC_STRUCT] [heading Description] BOOST_FUSION_DEFINE_ASSOC_STRUCT is a macro that can be used to generate all the necessary boilerplate to define and adapt an arbitrary struct as a model of __random_access_sequence__ and __associative_sequence__. [heading Synopsis] BOOST_FUSION_DEFINE_ASSOC_STRUCT( (namespace0)(namespace1)..., struct_name, (member_type0, member_name0, key_type0) (member_type1, member_name1, key_type1) ... ) [variablelist Notation [[`str`] [An instance of `struct_name`]] [[`e0`...`en`] [Heterogeneous values]] [[`fs`] [A __forward_sequence__]] ] [heading Expression Semantics] The above macro generates the necessary code that defines and adapts `struct_name` as a model of __random_access_sequence__ and __associative_sequence__. The sequence `(namespace0)(namespace1)...` declares the namespace for `struct_name`. It yields to a fully qualified name for `struct_name` of `namespace0::namespace1::... struct_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the struct is placed in the global namespace. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are part of the sequence. The macro should be used at global scope. Semantics of an expression is defined only where it differs from, or is not defined in __random_access_sequence__ and __associative_sequence__. [table [[Expression] [Semantics]] [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]] [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]] [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]] [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]] [[`str.member_nameN`] [Access of struct member `member_nameN`]] ] [heading Header] #include #include [heading Example] namespace keys { struct name; struct age; } // demo::employee is a Fusion sequence BOOST_FUSION_DEFINE_ASSOC_STRUCT( (demo), employee, (std::string, name, keys::name) (int, age, keys::age)) [endsect] [section:define_assoc_tpl_struct BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT] [heading Description] BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT is a macro that can be used to generate all the necessary boilerplate to define and adapt an arbitrary template struct as a model of __random_access_sequence__ and __associative_sequence__. [heading Synopsis] BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT( (template_param0)(template_param1)..., (namespace0)(namespace1)..., struct_name, (member_type0, member_name0, key_type0) (member_type1, member_name1, key_type1) ... ) [variablelist Notation [[`Str`] [An instantiated `struct_name`]] [[`str`] [An instance of `Str`]] [[`e0`...`en`] [Heterogeneous values]] [[`fs`] [A __forward_sequence__]] ] [heading Expression Semantics] The above macro generates the necessary code that defines and adapts `struct_name` as a model of __random_access_sequence__ and __associative_sequence__. The sequence `(template_param0)(template_param1)...` declares the names of the template type parameters used. The sequence `(namespace0)(namespace1)...` declares the namespace for `struct_name`. It yields to a fully qualified name for `struct_name` of `namespace0::namespace1::... struct_name`. If an empty namespace sequence is given (that is a macro that expands to nothing), the struct is placed in the global namespace. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are part of the sequence. The macro should be used at global scope. Semantics of an expression is defined only where it differs from, or is not defined in __random_access_sequence__ and __associative_sequence__. [table [[Expression] [Semantics]] [[`Str()`] [Creates an instance of `Str` with default constructed elements.]] [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]] [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]] [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]] [[`str.member_nameN`] [Access of struct member `member_nameN`]] ] [heading Header] #include #include [heading Example] namespace keys { struct name; struct age; } // Any instantiated demo::employee is a Fusion sequence BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT( (Name)(Age), (demo), employee, (Name, name, keys::name) (Age, age, keys::age)) [endsect] [endsect]