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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Function template for_each_field

boost::pfr::for_each_field

Synopsis

// In header: <boost/pfr/core.hpp>


template<typename T, typename F> void for_each_field(T && value, F && func);

Description

Calls func for each field of a value.

Example:

struct my_struct { int i, short s; };
int sum = 0;
for_each_field(my_struct{20, 22}, [&sum](const auto& field) { sum += field; });
assert(sum == 42);

Parameters:

func

must have one of the following signatures:

  • any_return_type func(U&& field) // field of value is perfect forwarded to function

  • any_return_type func(U&& field, std::size_t i)

  • any_return_type func(U&& value, I i) // Here I is an std::integral_constant<size_t, field_index>

value

To each field of this variable will be the func applied.


PrevUpHomeNext