Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Function template for_each_field_with_name

pfr::for_each_field_with_name

Synopsis

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


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

Description

Calls func for each field with its name of a value

Example:

struct Toto { int a; char c; };
Toto t {5, 'c'};
auto print = [](std::string_view name, const auto& value){ std::cout << "Name: " << name << " Value: " << value << std::endl; };
for_each_field_with_name(t, print);

Parameters:

func

must have one of the following signatures:

  • any_return_type func(std::string_view name, U&& field) // field of value is perfect forwarded to function

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

  • any_return_type func(std::string_view name, 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