mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-30 12:37:29 +02:00
DOC: Document the BOOST_FUSION_AUTO* macros.
This documents the AUTO_ADAPT macros : * BOOST_FUSION_AUTO_ADAPT_STRUCT * BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED * BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT * BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED
This commit is contained in:
172
doc/adapted.qbk
172
doc/adapted.qbk
@ -177,7 +177,7 @@ __boost_tuple_library__
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_struct BOOST_FUSION_ADAPT_STRUCT]
|
[section:adapt_struct BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT]
|
||||||
|
|
||||||
[heading Description]
|
[heading Description]
|
||||||
BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
|
BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
|
||||||
@ -192,13 +192,22 @@ __random_access_sequence__.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_STRUCT(
|
||||||
|
struct_name,
|
||||||
|
(member_name0)
|
||||||
|
(member_name1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
[heading Semantics]
|
[heading Semantics]
|
||||||
|
|
||||||
The above macro generates the necessary code to adapt `struct_name`
|
The above macro generates the necessary code to adapt `struct_name`
|
||||||
as a model of __random_access_sequence__.
|
as a model of __random_access_sequence__.
|
||||||
The sequence of `(member_typeN, member_nameN)`
|
The sequence of `(member_typeN, member_nameN)`
|
||||||
pairs declares the type and names of each of the struct members that are
|
pairs declares the type and names of each of the struct members that are
|
||||||
part of the sequence.
|
part of the sequence. While the auto version of the macro only allows
|
||||||
|
specifying a sequence of `(member_nameN)` as fields' types are deduced with
|
||||||
|
[@boost:/libs/typeof/index.html Boost.TypeOf].
|
||||||
|
|
||||||
The macro should be used at global scope, and `struct_name` should be the fully
|
The macro should be used at global scope, and `struct_name` should be the fully
|
||||||
namespace qualified name of the struct to be adapted.
|
namespace qualified name of the struct to be adapted.
|
||||||
@ -206,9 +215,10 @@ namespace qualified name of the struct to be adapted.
|
|||||||
[heading Header]
|
[heading Header]
|
||||||
|
|
||||||
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
|
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
|
||||||
|
#include <boost/fusion/adapted/struct/auto_adapt_struct.hpp>
|
||||||
#include <boost/fusion/include/adapt_struct.hpp>
|
#include <boost/fusion/include/adapt_struct.hpp>
|
||||||
|
|
||||||
[heading Example]
|
[heading Example: BOOST_FUSION_ADAPT_STRUCT ]
|
||||||
namespace demo
|
namespace demo
|
||||||
{
|
{
|
||||||
struct employee
|
struct employee
|
||||||
@ -224,6 +234,23 @@ namespace qualified name of the struct to be adapted.
|
|||||||
(std::string, name)
|
(std::string, name)
|
||||||
(int, age))
|
(int, age))
|
||||||
|
|
||||||
|
|
||||||
|
[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT ]
|
||||||
|
namespace demo
|
||||||
|
{
|
||||||
|
struct employee
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
int age;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// demo::employee is now a Fusion sequence
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_STRUCT(
|
||||||
|
demo::employee,
|
||||||
|
(name)
|
||||||
|
(age))
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT]
|
[section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT]
|
||||||
@ -284,7 +311,7 @@ namespace qualified name of the struct to be adapted.
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED]
|
[section:adapt_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT_NAMED]
|
||||||
|
|
||||||
[heading Description]
|
[heading Description]
|
||||||
BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are
|
BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are
|
||||||
@ -292,6 +319,7 @@ 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
|
arbitrary struct a model of __random_access_sequence__. The given struct is
|
||||||
adapted using the given name.
|
adapted using the given name.
|
||||||
|
|
||||||
|
|
||||||
[heading Synopsis]
|
[heading Synopsis]
|
||||||
BOOST_FUSION_ADAPT_STRUCT_NAMED(
|
BOOST_FUSION_ADAPT_STRUCT_NAMED(
|
||||||
struct_name, adapted_name,
|
struct_name, adapted_name,
|
||||||
@ -300,6 +328,13 @@ adapted using the given name.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(
|
||||||
|
struct_name, adapted_name,
|
||||||
|
(member_name0)
|
||||||
|
(member_name1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
|
BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
|
||||||
struct_name,
|
struct_name,
|
||||||
(namespace0)(namespace1)...,
|
(namespace0)(namespace1)...,
|
||||||
@ -309,6 +344,17 @@ adapted using the given name.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS(
|
||||||
|
struct_name,
|
||||||
|
(namespace0)(namespace1)...,
|
||||||
|
adapted_name,
|
||||||
|
(member_name0)
|
||||||
|
(member_name1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[heading Semantics]
|
[heading Semantics]
|
||||||
|
|
||||||
The above macros generate the necessary code to adapt `struct_name`
|
The above macros generate the necessary code to adapt `struct_name`
|
||||||
@ -321,9 +367,11 @@ If an empty namespace sequence is given (that is a macro that expands to
|
|||||||
nothing), the adapted view is placed in the global namespace.
|
nothing), the adapted view is placed in the global namespace.
|
||||||
If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the
|
If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the
|
||||||
adapted view is placed in the namespace `boost::fusion::adapted`.
|
adapted view is placed in the namespace `boost::fusion::adapted`.
|
||||||
The sequence of `(member_typeN, member_nameN)`
|
In the non-auto version of the macro the sequence of
|
||||||
pairs declares the type and names of each of the struct members that are
|
`(member_typeN, member_nameN)` pairs declares the type and names of each of the
|
||||||
part of the sequence.
|
struct members that are part of the sequence.
|
||||||
|
While the auto version of the macro only allows specifying a sequence of
|
||||||
|
`(member_nameN)` as fields' types are deduced with [@boost:/libs/typeof/index.html Boost.TypeOf].
|
||||||
|
|
||||||
The macros should be used at global scope, and `struct_name` should be the fully
|
The macros should be used at global scope, and `struct_name` should be the fully
|
||||||
namespace qualified name of the struct to be converted.
|
namespace qualified name of the struct to be converted.
|
||||||
@ -331,9 +379,10 @@ namespace qualified name of the struct to be converted.
|
|||||||
[heading Header]
|
[heading Header]
|
||||||
|
|
||||||
#include <boost/fusion/adapted/struct/adapt_struct_named.hpp>
|
#include <boost/fusion/adapted/struct/adapt_struct_named.hpp>
|
||||||
|
#include <boost/fusion/adapted/struct/auto_adapt_struct_named.hpp>
|
||||||
#include <boost/fusion/include/adapt_struct_named.hpp>
|
#include <boost/fusion/include/adapt_struct_named.hpp>
|
||||||
|
|
||||||
[heading Example]
|
[heading Example: BOOST_FUSION_ADAPT_STRUCT_NAMED]
|
||||||
namespace demo
|
namespace demo
|
||||||
{
|
{
|
||||||
struct employee
|
struct employee
|
||||||
@ -350,9 +399,26 @@ namespace qualified name of the struct to be converted.
|
|||||||
(std::string, name)
|
(std::string, name)
|
||||||
(int, age))
|
(int, age))
|
||||||
|
|
||||||
|
[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED]
|
||||||
|
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_AUTO_ADAPT_STRUCT_NAMED(
|
||||||
|
demo::employee, adapted_employee,
|
||||||
|
(name)
|
||||||
|
(age))
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT]
|
[section:adapt_assoc BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT]
|
||||||
|
|
||||||
[heading Description]
|
[heading Description]
|
||||||
BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
|
BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
|
||||||
@ -367,13 +433,24 @@ __random_access_sequence__ and __associative_sequence__.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT(
|
||||||
|
struct_name,
|
||||||
|
(member_name0, key_type0)
|
||||||
|
(member_name1, key_type1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
[heading Semantics]
|
[heading Semantics]
|
||||||
|
|
||||||
The above macro generates the necessary code to adapt `struct_name`
|
The above macro generates the necessary code to adapt `struct_name`
|
||||||
as a model of __random_access_sequence__ and __associative_sequence__.
|
as a model of __random_access_sequence__ and __associative_sequence__.
|
||||||
The sequence of `(member_typeN, member_nameN, key_typeN)`
|
The sequence of `(member_typeN, member_nameN, key_typeN)`
|
||||||
triples declares the type, name and key type of each of the struct members
|
triples declares the type, name and key type of each of the struct members
|
||||||
that are part of the sequence.
|
that are part of the sequence.
|
||||||
|
|
||||||
|
While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT only allows specifying a sequence of
|
||||||
|
`(member_nameN, key_typeN)` as fields' types are deduced with
|
||||||
|
[@boost:/libs/typeof/index.html Boost.TypeOf].
|
||||||
|
|
||||||
The macro should be used at global scope, and `struct_name` should be the fully
|
The macro should be used at global scope, and `struct_name` should be the fully
|
||||||
namespace qualified name of the struct to be adapted.
|
namespace qualified name of the struct to be adapted.
|
||||||
@ -381,9 +458,10 @@ namespace qualified name of the struct to be adapted.
|
|||||||
[heading Header]
|
[heading Header]
|
||||||
|
|
||||||
#include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
|
#include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
|
||||||
|
#include <boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp>
|
||||||
#include <boost/fusion/include/adapt_assoc_struct.hpp>
|
#include <boost/fusion/include/adapt_assoc_struct.hpp>
|
||||||
|
|
||||||
[heading Example]
|
[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT]
|
||||||
namespace demo
|
namespace demo
|
||||||
{
|
{
|
||||||
struct employee
|
struct employee
|
||||||
@ -407,6 +485,30 @@ namespace qualified name of the struct to be adapted.
|
|||||||
(std::string, name, keys::name)
|
(std::string, name, keys::name)
|
||||||
(int, age, keys::age))
|
(int, age, keys::age))
|
||||||
|
|
||||||
|
[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT]
|
||||||
|
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_AUTO_ADAPT_ASSOC_STRUCT(
|
||||||
|
demo::employee,
|
||||||
|
(name, keys::name)
|
||||||
|
(age, keys::age))
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT]
|
[section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT]
|
||||||
@ -475,7 +577,7 @@ namespace qualified name of the struct to be adapted.
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED]
|
[section:adapt_assoc_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT_NAMED]
|
||||||
|
|
||||||
[heading Description]
|
[heading Description]
|
||||||
BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are
|
BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are
|
||||||
@ -491,6 +593,13 @@ __associative_sequence__. The given struct is adapted using the given name.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED(
|
||||||
|
struct_name, adapted_name,
|
||||||
|
(member_name0, key_type0)
|
||||||
|
(member_name1, key_type1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS(
|
BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS(
|
||||||
struct_name,
|
struct_name,
|
||||||
(namespace0)(namespace1)...,
|
(namespace0)(namespace1)...,
|
||||||
@ -500,6 +609,15 @@ __associative_sequence__. The given struct is adapted using the given name.
|
|||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_NS(
|
||||||
|
struct_name,
|
||||||
|
(namespace0)(namespace1)...,
|
||||||
|
adapted_name,
|
||||||
|
(member_name0, key_type0)
|
||||||
|
(member_name1, key_type1)
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
[heading Semantics]
|
[heading Semantics]
|
||||||
|
|
||||||
The above macros generate the necessary code to adapt `struct_name`
|
The above macros generate the necessary code to adapt `struct_name`
|
||||||
@ -516,15 +634,20 @@ The sequence of `(member_typeN, member_nameN, key_typeN)`
|
|||||||
triples declares the type, name and key type of each of the struct members
|
triples declares the type, name and key type of each of the struct members
|
||||||
that are part of the sequence.
|
that are part of the sequence.
|
||||||
|
|
||||||
|
While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED only allows specifying a
|
||||||
|
sequence of `(member_nameN, key_typeN)` as fields' types are deduced with
|
||||||
|
[@boost:/libs/typeof/index.html Boost.TypeOf].
|
||||||
|
|
||||||
The macros should be used at global scope, and `struct_name` should be the fully
|
The macros should be used at global scope, and `struct_name` should be the fully
|
||||||
namespace qualified name of the struct to be converted.
|
namespace qualified name of the struct to be converted.
|
||||||
|
|
||||||
[heading Header]
|
[heading Header]
|
||||||
|
|
||||||
#include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
|
#include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
|
||||||
|
#include <boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp>
|
||||||
#include <boost/fusion/include/adapt_assoc_struct_named.hpp>
|
#include <boost/fusion/include/adapt_assoc_struct_named.hpp>
|
||||||
|
|
||||||
[heading Example]
|
[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED]
|
||||||
namespace demo
|
namespace demo
|
||||||
{
|
{
|
||||||
struct employee
|
struct employee
|
||||||
@ -547,6 +670,29 @@ namespace qualified name of the struct to be converted.
|
|||||||
(std::string, name, keys::name)
|
(std::string, name, keys::name)
|
||||||
(int, age, keys::age))
|
(int, age, keys::age))
|
||||||
|
|
||||||
|
[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED]
|
||||||
|
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_AUTO_ADAPT_ASSOC_STRUCT_NAMED(
|
||||||
|
demo::employee, adapted_employee,
|
||||||
|
(name, keys::name)
|
||||||
|
(age, keys::age))
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_adt BOOST_FUSION_ADAPT_ADT]
|
[section:adapt_adt BOOST_FUSION_ADAPT_ADT]
|
||||||
|
Reference in New Issue
Block a user