| Home | Libraries | People | FAQ | More

### BOOST_FUSION_ADAPT_TPL_STRUCT

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

##### Synopsis

    BOOST_FUSION_ADAPT_TPL_STRUCT(
        (template_param0)(template_param1)...,
        (struct_name) (specialization_param0)(specialization_param1)...,
        member_name0,
        member_name1
        ...
        )

    // Without BOOST_PP_VARIADICS support :
    BOOST_FUSION_ADAPT_TPL_STRUCT(
        (template_param0)(template_param1)...,
        (struct_name) (specialization_param0)(specialization_param1)...,
        (member_type0, member_name0)
        (member_type1, member_name1)
        (auto, member_name2),
        ...
        )

##### 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_nameN,` arguments or `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are part of the sequence.

When member_typeN is omitted or set to auto, the type is infered with Boost.TypeOf.

The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted.

##### Header

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

##### Example

    namespace demo
    {
        template<typename Name, typename Age>
        struct employee
        {
            Name name;
            Age age;
            int employment_timestamp;
        };
    }

    // Any instantiated demo::employee is now a Fusion sequence
    BOOST_FUSION_ADAPT_TPL_STRUCT(
        (Name)(Age),
        (demo::employee) (Name)(Age),
        (Name, name)
        (Age, age)
        (auto, employment_timestamp))

    // Or by infering type completely
    BOOST_FUSION_ADAPT_TPL_STRUCT(
        (Name)(Age),
        (demo::employee) (Name)(Age),
        name,
        age,
        employment_timestamp)