Make io_fields print field names

Phil Phil via Boost-users <[email protected]> Fri, 5 Sep 2025 13:56:51 +0000
Newsgroups gmane.comp.lib.boost.user
Message-ID <DS0PR22MB40516F4F487E51AACAD9CA01AA03A@DS0PR22MB4051.namprd22.prod.outlook.com>
Greetings,

I'd like to replace a call to io_fields like this


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

In such a way that the names of the fields are printed too so it should something like

os << "{ " << "x: " << x.i << " ,"  << "y: " <<  x.s << " }"

Is this possible and if yes what would be the most straightforward way?

Regards

_______________________________________________
Boost-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost-users.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/ZQOGJENMFEGGGHBXLI4AMKWOWEJI7UCX/