mirror of
https://github.com/boostorg/fusion.git
synced 2025-08-02 05:54:37 +02:00
Adding documentation of the new ADAPT_STRUCT and ADAPT_STRUCT_TPL macros,
capable of deducing type.
This commit is contained in:
@@ -177,7 +177,7 @@ __boost_tuple_library__
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:adapt_struct BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT]
|
[section:adapt_struct BOOST_FUSION_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
|
||||||
@@ -187,15 +187,18 @@ __random_access_sequence__.
|
|||||||
[heading Synopsis]
|
[heading Synopsis]
|
||||||
BOOST_FUSION_ADAPT_STRUCT(
|
BOOST_FUSION_ADAPT_STRUCT(
|
||||||
struct_name,
|
struct_name,
|
||||||
(member_type0, member_name0)
|
member_name0,
|
||||||
(member_type1, member_name1)
|
member_name1,
|
||||||
|
member_name2,
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// When Variadic support isn't available or you wish to manually specify the type:
|
||||||
BOOST_FUSION_AUTO_ADAPT_STRUCT(
|
BOOST_FUSION_AUTO_ADAPT_STRUCT(
|
||||||
struct_name,
|
struct_name,
|
||||||
(member_name0)
|
(member_type0, member_name0)
|
||||||
(member_name1)
|
(member_type1, member_name1)
|
||||||
|
(BOOST_FUSION_ADAPT_AUTO, member_name2)
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -203,11 +206,13 @@ __random_access_sequence__.
|
|||||||
|
|
||||||
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)`
|
|
||||||
pairs declares the type and names of each of the struct members that are
|
The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
|
||||||
part of the sequence. While the auto version of the macro only allows
|
pairs declares the type and names of each of the struct members that are part of
|
||||||
specifying a sequence of `(member_nameN)` as fields' types are deduced with
|
the sequence.
|
||||||
[@boost:/libs/typeof/index.html Boost.TypeOf].
|
|
||||||
|
Omitting the type or using BOOST_FUSION_ADAPT_AUTO can be used to infer the type,
|
||||||
|
as with decltype.
|
||||||
|
|
||||||
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.
|
||||||
@@ -215,7 +220,6 @@ 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: BOOST_FUSION_ADAPT_STRUCT ]
|
[heading Example: BOOST_FUSION_ADAPT_STRUCT ]
|
||||||
@@ -231,25 +235,15 @@ namespace qualified name of the struct to be adapted.
|
|||||||
// demo::employee is now a Fusion sequence
|
// demo::employee is now a Fusion sequence
|
||||||
BOOST_FUSION_ADAPT_STRUCT(
|
BOOST_FUSION_ADAPT_STRUCT(
|
||||||
demo::employee,
|
demo::employee,
|
||||||
(std::string, name)
|
name,
|
||||||
(int, age))
|
age)
|
||||||
|
|
||||||
|
// Or demo::employee is also a Fusion sequence
|
||||||
[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT ]
|
BOOST_FUSION_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,
|
demo::employee,
|
||||||
(name)
|
(BOOST_FUSION_ADAPT_AUTO, name)
|
||||||
(age))
|
(BOOST_FUSION_ADAPT_AUTO, age)
|
||||||
|
)
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@@ -261,11 +255,21 @@ necessary boilerplate to make an arbitrary template struct a model of
|
|||||||
__random_access_sequence__.
|
__random_access_sequence__.
|
||||||
|
|
||||||
[heading Synopsis]
|
[heading Synopsis]
|
||||||
|
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
||||||
|
(template_param0)(template_param1)...,
|
||||||
|
(struct_name) (specialization_param0)(specialization_param1)...,
|
||||||
|
member_name0,
|
||||||
|
member_name1
|
||||||
|
...
|
||||||
|
)
|
||||||
|
|
||||||
|
// When Variadic support isn't available or you wish to manually specify the type:
|
||||||
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
||||||
(template_param0)(template_param1)...,
|
(template_param0)(template_param1)...,
|
||||||
(struct_name) (specialization_param0)(specialization_param1)...,
|
(struct_name) (specialization_param0)(specialization_param1)...,
|
||||||
(member_type0, member_name0)
|
(member_type0, member_name0)
|
||||||
(member_type1, member_name1)
|
(member_type1, member_name1)
|
||||||
|
(BOOST_FUSION_ADAPT_AUTO, member_name2),
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -279,9 +283,12 @@ the template type parameters used.
|
|||||||
The sequence `(specialization_param0)(specialization_param1)...`
|
The sequence `(specialization_param0)(specialization_param1)...`
|
||||||
declares the template parameters of the actual specialization of `struct_name`
|
declares the template parameters of the actual specialization of `struct_name`
|
||||||
that is adapted as a fusion sequence.
|
that is adapted as a fusion sequence.
|
||||||
The sequence of `(member_typeN, member_nameN)`
|
The sequence of `member_nameN,` arguments or `(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
|
||||||
part of the sequence.
|
the sequence.
|
||||||
|
|
||||||
|
Omitting the type or using BOOST_FUSION_ADAPT_AUTO can be used to infer the type,
|
||||||
|
as with decltype.
|
||||||
|
|
||||||
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.
|
||||||
@@ -299,6 +306,7 @@ namespace qualified name of the struct to be adapted.
|
|||||||
{
|
{
|
||||||
Name name;
|
Name name;
|
||||||
Age age;
|
Age age;
|
||||||
|
int employment_timestamp;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +315,16 @@ namespace qualified name of the struct to be adapted.
|
|||||||
(Name)(Age),
|
(Name)(Age),
|
||||||
(demo::employee) (Name)(Age),
|
(demo::employee) (Name)(Age),
|
||||||
(Name, name)
|
(Name, name)
|
||||||
(Age, age))
|
(Age, age)
|
||||||
|
(BOOST_FUSION_ADAPT_AUTO, employment_timestamp))
|
||||||
|
|
||||||
|
// Or by infering type completely
|
||||||
|
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
||||||
|
(Name)(Age),
|
||||||
|
(demo::employee) (Name)(Age),
|
||||||
|
name,
|
||||||
|
age,
|
||||||
|
employment_timestamp)
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user