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

Click here to view the latest version of this page.
PrevUpHomeNext

BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT

Description

BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT is a macro that can be used to generate all the necessary boilerplate to define and adapt an arbitrary template struct as a model of Random Access Sequence and Associative Sequence.

Synopsis
BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
    (namespace0)(namespace1)...,
    (template_param0)(template_param1)...,
    struct_name,
    (member_type0, member_name0, key_type0)
    (member_type1, member_name1, key_type1)
    ...
    )

Notation

Str

An instantiated struct_name

str

An instance of Str

e0...en

Heterogeneous values

fs

A Forward Sequence

Expression Semantics

The above macro generates the necessary code that defines and adapts struct_name as a model of Random Access Sequence and Associative Sequence. The sequence (namespace0)(namespace1)... declares the namespace for struct_name. It yields to a fully qualified name for struct_name of namespace0::namespace1::... struct_name. If an empty namespace sequence is given, the struct is placed in the global namespace. The sequence (template_param0)(template_param1)... declares the names of the template type parameters used. 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 macro should be used at global scope. Semantics of an expression is defined only where it differs from, or is not defined in Random Access Sequence and Associative Sequence.

Expression

Semantics

Str()

Creates an instance of Str with default constructed elements.

Str(e0, e1,... en)

Creates an instance of Str with elements e0...en.

Str(fs)

Copy constructs an instance of Str from a Forward Sequence fs.

str = fs

Assigns from a Forward Sequence fs.

str.member_nameN

Access of struct member member_nameN

Header
#include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
#include <boost/fusion/include/define_assoc_struct.hpp>
Example
namespace keys
{
    struct name;
    struct age;
}

// Any instantiated demo::employee is a Fusion sequence
BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
    (demo), (Name)(Age), employee,
    (Name, name, keys::name)
    (Age, age, keys::age))

PrevUpHomeNext