![]() |
Home | Libraries | People | FAQ | More |
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.
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, namespace_list, adapted_name, (member_type0, member_name0, key_type0) (member_type1, member_name1, key_type1) ... )
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 of (member_typeN,
member_nameN,
key_typeN)
triples declares the type, name and key type of each of the struct members
that will be part of the sequence. namespace_list
specifies the C++ namespace of the adapted_name.
It has the format of (ns1)(ns2)...,
which results in a fully qualified adapted name of ns1::ns2::adapted_name. If an empty namespace_list is given, the adapted view
is placed in the global namespace. If no namespace list is given (i.e. BOOST_FUSION_ADAPT_STRUCT_ASSOC_NAMED),
the adapted view is placed in the namespace boost::fusion::adapted.
The macro should be used at global scope, and struct_name
should be the fully namespace qualified name of the struct to be converted.
#include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp> #include <boost/fusion/include/adapt_assoc_struct_named.hpp>
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))