Boost C++ Libraries Home Libraries People FAQ More

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 into a Random Access Sequence. The given struct is adapted using the given name.

Synopsis
BOOST_FUSION_ADAPT_STRUCT_NAMED(
    struct_name, adapted_name
    (member_type0, member_name0)
    (member_type1, member_name1)
    ...
    )

BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
    struct_name, namespace_list, adapted_name
    (member_type0, member_name0)
    (member_type1, member_name1)
    ...
    )
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 of (member_typeN, member_nameN) pairs declare the type and names of each of the struct members that will be part of the sequence. The 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 no namespace list is given (i.e. BOOST_FUSION_ADAPT_STRUCT_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.

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
    (std::string, name)
    (int, age))

PrevUpHomeNext