| Home | Libraries | People | FAQ | More

### BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED

##### 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.

##### 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)
        ...
        )

##### 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.

##### Header

    #include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
    #include <boost/fusion/include/adapt_assoc_struct_named.hpp>

##### 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))