Boost C++ Libraries 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.

Function template io_fields



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

template<typename T> auto io_fields(T && value);


IO manipulator to read/write simple aggregate value field-by-field.


struct my_struct {
    int i;
    short s;

std::ostream& operator<<(std::ostream& os, const my_struct& x) {
    return os << boost::pfr::io_fields(x);  // Equivalent to: os << "{ " << x.i << " ," <<  x.s << " }"

std::istream& operator>>(std::istream& is, my_struct& x) {
    return is >> boost::pfr::io_fields(x);  // Equivalent to: is >> "{ " >> x.i >> " ," >>  x.s >> " }"

Input and output streaming operators for boost::pfr::io_fields are symmetric, meaning that you get the original value by streaming it and reading back if each fields streaming operator is symmetric.

See Also : 'Custom printing of aggregates' for info on how to implement your own manipulator with custom format.