|
BDE 4.39.x Production Release
|
Provide a container of arguments for use by bsl::format.
Provide a container of arguments for use by bsl::format
bsl_format.h
This component provides an implementation of the C++20 Standard Library's std::basic_format_args, providing access to an array of basic_format_arg types. It also provides implementations of the standard library free functions make_format_args and make_wformat_args .
As also specified by the standard, the provided free functions return an exposition-only type that holds references to the arguments passed in. A basic_format_args constructed from an instance of this type holds a reference to it. This means it is the users responsibility to ensure that the lifetime of the returned type does not end before the lifetime of the constructed basic_format_args type. This means that, for example, the following code results in Undefined Behavior, in both the standard library and the bslfmt versions:
This header is not intended to be included directly. Please include <bsl_format.h> to be able to use bsl::basic_format_args.
In this section we show the intended use of this component.
We do not expect most users of bsl::format to interact with this type directly and instead use bsl::format or bsl::vformat. In addition, there are only a very limited number of public methods so this example is necessarily unrealistic.
Suppose we want to construct a int-containing basic_format_args and verify that it contains that int. Note the use of a function to workaround the lifetime issues specified above. Format_ArgsStore passed to the basic_format_args constructor must outlive the constructed object. bslfmt::make_format_args returns temporary Format_ArgsStore object so to avoid its destruction we have to do all the useful work within the execution of one function.