Reputation: 5138
I recently encountered code similar to this:
std::string myString = "test";
boost::format fmt("%s");
fmt % myString;
What is the (second) % operator doing here?
EDIT:
I understand the end result, but I could not find a definition of how the % operator can be used like this.
Can someone provide an example that explains what exactly the meaning of the % operator is here?
Upvotes: 0
Views: 120
Reputation: 546015
I understand the end result, but I could not find a definition of how the % operator can be used like this.
operator %
can be overloaded. Boost.Format does exactly that for its basic_format
class:
template<class T>
basic_format& operator%(const T& x)
{ return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }
This member function gets invoked whenever you use the code fmt % value
where fmt
is of type boost::basic_format<Ch>
.
Upvotes: 3