Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Function template for_each_field

pfr::for_each_field

Synopsis

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


template<typename T, typename F> 
  constexpr 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;
pfr::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