|
BDE 4.39.x Production Release
|
Provide a formatter that uses the ostream insert operator<<.
Provide a formatter that uses the ostream insert operator<<.
ostream operator<<@SEE ALSO: bslfmt_streamed, bslfmt_enablestreamedformatter
This component provides a base formatter template that may be used to enable bsl::formating of values that have an ostream insert operator<< implemented. The formatting template is also compatible with std::format on platforms where it is provided. Note that this component is not recommended to be used directly but mainly via the bslfmt_streamed component that provides a formattable-wrapper, or by defining the bslfmt_enablestreamedformatter nested trait in the class or template that should have a permanent streamed formatter.
The use case for this component is very narrow, so please read the package documentation before using it and possibly locking yourself into forever supporting an inadequate format string specification.
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 the type with a streaming operator, but without a formatter specialization:
Then, we enable formatting of this type using bslfmt::StreamedFormatter as its implementation:
Next, we create an instance of this type and use bsl::format to format it:
Finally, we verify the output is correct: