Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing std::quoted(str) to boost::format

std::quoted is designed to work with standard IOStreams, and boost::format uses such a stream. Because boost::format is specified to work with user-defined types, the latter is not an implementation detail. So it did not surprise me that this compiles:

boost::format("%1%") % std::quoted(std::string{"Hello, world"});

But to me, this seems on the boundary of an implementation detail. Is this supposed to work? And is this portable? std::quoted has an unspecified return type, and it's not clear that passing it via operator% would work.

like image 549
MSalters Avatar asked Mar 17 '26 19:03

MSalters


1 Answers

It is supposed to work: How It Works and Rationale:

accept any types of variables, by relying on streams for the actual conversion to string. This specifically concerns user-defined types, for which the formatting options effects should be intuitively natural.

like image 81
sehe Avatar answered Mar 20 '26 10:03

sehe