BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslfmt_format_imp

Detailed Description

Provide a standard compliant format implementation.

Outline

Purpose

Provide a standard compliant format implementation

Classes

Canonical Header

bsl_format.h

See also
ISO C++ Standard, <format>

Description

This component will provide, in the bslfmt namespace, compliant implementations of the following free functions exposed by the standard <format> header. These are available for C++03 and later.

Note 1: The overloads taking a locale parameter are not provided. Note 2: Compile-time format string checking is not performed.

This header is not intended to be included directly. Please include <bsl_format.h> to be able to use bsl::format_to_n_result.

User-provided formatters

User-provided formatters are supported by the BSL implementation, just as they are by the standard library implementation. However, in order for them to be compatible with both implementations, there are specific requirements, notably:

An example of a user defined formatter is as follows:

namespace bsl {
template <class t_CHAR> struct formatter<UserDefinedType, t_CHAR> {
template <class t_PARSE_CONTEXT>
t_PARSE_CONTEXT::iterator parse(t_PARSE_CONTEXT& pc)
{
// implementation goes here
}
template <class t_FORMAT_CONTEXT>
t_FORMAT_CONTEXT::iterator format(UserDefinedType s,
t_FORMAT_CONTEXT& ctx) const
{
// implementation goes here
}
};
} // close namespace bsl
#define BSLS_KEYWORD_CONSTEXPR_CPP20
Definition bsls_keyword.h:645
Definition bdlat_valuetypefunctions.h:939

Usage

This section illustrates the intended use of this component.

Example 1: Simple integer formatting

#include <bslfmt_format.h>
#include <bsl_iostring.h>
bsl::string doFormat(int value)
{
bsl::string res = bslfmt::format("{}", value);
return res;
}
int main()
{
bsl::cout << doFormat(99) << bsl::endl;
return 0;
}
Definition bslstl_string.h:1252
bsl::string format(BSLFMT_FORMAT_STRING_PARAMETER fmtStr, const t_ARGS &... args)
Definition bslfmt_format_imp.h:1085

Macro Definition Documentation

◆ BSLFMT_FORMAT_STRING_PARAMETER

#define BSLFMT_FORMAT_STRING_PARAMETER   bslfmt::format_string

◆ BSLFMT_FORMAT_WSTRING_PARAMETER

#define BSLFMT_FORMAT_WSTRING_PARAMETER   bslfmt::wformat_string