|
BDE 4.39.x Production Release
|
Provide a wrapper to format using an ostream operator<<
Provide a wrapper to format using an ostream operator<<
ostream operator<<This component provides both a wrapper class template and a function template for creating a wrapper that enables bsl::formating values that offer an ostream insert operator<<. This wrapper is also compatible with std::format on platforms where it is provided.
Using the bslfmt::streamed free function may be preferred to using the bslfmt::Streamed type directly because the bslfmt::streamed free-function supports simpler syntax on platforms that do not support class template argument deduction (CTAD, introduced in C++17).
For more (important) information please see the package documentation .
In this section we show the intended use of this component.
Suppose we want to format an object that already supports streaming into an ostream using the insert operator<<.
First, we define a type with a streaming operator but without a formatter specialization:
Then we create an instance of this type and use bsl::streamed to allow us to format it:
Next, we format the "value" using bsl::format with the wrapper-creator function:
Finally, we verify the output is correct: