Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Function template io_fields

pfr::io_fields

Synopsis

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


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

Description

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

Example:

struct my_struct {
    int i;
    short s;
};

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

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

Input and output streaming operators for 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.


PrevUpHomeNext