Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

BOOST_FUSION_ADAPT_STRUCT_NAMED

Description

BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_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. The given struct is adapted using the given name.

Synopsis
BOOST_FUSION_ADAPT_STRUCT_NAMED(
    struct_name, adapted_name,
    member_name0,
    member_name1,
    member_name2,
    ...
    )

BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
    struct_name,
    (namespace0)(namespace1)...,
    adapted_name,
    member_name0,
    member_name1,
    member_name2,
    ...
    )

// Without BOOST_PP_VARIADICS support :

BOOST_FUSION_ADAPT_STRUCT_NAMED(
    struct_name, adapted_name,
    (member_type0, member_name0)
    (member_type1, member_name1)
    (BOOST_FUSION_ADAPT_AUTO, member_name2),
    ...
    )

BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
    struct_name,
    (namespace0)(namespace1)...,
    adapted_name,
    (member_type0, member_name0)
    (member_type1, member_name1)
    (BOOST_FUSION_ADAPT_AUTO, member_name2),
    ...
    )
Semantics

The above macros generate the necessary code to adapt struct_name as a model of Random Access 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_NAMED), the adapted view is placed in the namespace boost::fusion::adapted. 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 BOOST_FUSION_ADAPT_AUTO, the type is infered with Boost.TypeOf.

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_struct_named.hpp>
#include <boost/fusion/include/adapt_struct_named.hpp>
Example
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_ADAPT_STRUCT_NAMED(
    demo::employee, adapted_employee,
    name,
    age)

// Without BOOST_PP_VARIADICS support :
BOOST_FUSION_ADAPT_STRUCT_NAMED(
    demo::employee, adapted_employee,
    (BOOST_FUSION_ADAPT_AUTO, name),
    (BOOST_FUSION_ADAPT_AUTO, age))

PrevUpHomeNext