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

Detailed Description

Provide a string_view wrapper for formatting library usage.

Outline

Purpose

Provide a string_view wrapper for formatting library usage

Classes

Canonical Header

bsl_format.h

Description

This component provides an implementation of the C++20 Standard Library's basic_format_string , providing wrapper around string_view for format specification strings.

Using this rather than string_view directly serves three main purposes:

Suppression of the argument deduction that would normally result in a compile-time error requires that we use intermediate template aliases for format_string and wformat_string . As this is not possible under C++03, usage of this type necessarily differs under C++03. This is acceptable as this type is typically only used internally within the bslfmt::format family of functions.

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

Usage

In this section we show the intended use of this component.

Example: Own format function

This usage example reflects how bslfmt::format typically uses this type.

Suppose we have a function that takes a format string and requires that the string be constant evaluated under C++20:

#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES) &&
defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
template <class t_ARG>
void myFormatLikeFunction(bslfmt::format_string<t_ARG> fmtstr,
const t_ARG&)
{
assert(fmtstr.get() == "{:}");
}
#else
template <class t_ARG>
void myFormatLikeFunction(bslfmt::format_string fmtstr,
const t_ARG&)
{
assert(fmtstr.get() == "{:}");
}
#endif
basic_format_string< char > format_string
Definition bslfmt_format_string.h:255

We can then invoke our function:

int value = 5;
myFormatLikeFunction("{:}", value);