Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Standard format specification | ||||
Formatting functions | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
Format strings | ||||
(C++20)(C++20)(C++20) | ||||
runtime_format (C++26) | ||||
Formatting concepts | ||||
(C++23) | ||||
Formatter | ||||
(C++20) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++23) | ||||
(C++23) | ||||
Formatting arguments | ||||
(C++20) | ||||
(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(deprecated in C++26) | ||||
(C++20)(C++20) | ||||
Format error | ||||
(C++20) |
Defined in header <format> | ||
/*runtime-format-string*/<char> runtime_format(std::string_view fmt)noexcept; | (1) | (since C++26) |
/*runtime-format-string*/<wchar_t> runtime_format(std::wstring_view fmt)noexcept; | (2) | (since C++26) |
Returns an object that stores a runtime format string directly usable in user-oriented formatting functions and can be implicitly converted tostd::basic_format_string
.
Contents |
fmt | - | a string view |
An object holding the runtime format string of the exposition-only type:
runtime-format-string
<CharT>
template<class CharT> struct/*runtime-format-string*/; | (exposition only*) | |
The returned object contains an exposition-only non-static data memberstr
of typestd::basic_string_view<CharT>.
/*runtime-format-string*/(std::basic_string_view<CharT> s)noexcept; | (1) | |
/*runtime-format-string*/(const/*runtime-format-string*/&)= delete; | (2) | |
/*runtime-format-string*/& operator=(const/*runtime-format-string*/&)= delete; | (3) | |
str
withs
.Since the return type ofruntime_format
is neither copyable nor movable, an attempt of passingruntime_fmt as glvalue inhibits the construction ofstd::basic_format_string which results in program ill-formed. To constructstd::basic_format_string
withruntime_format
, the returned value ofruntime_format
is passed directly onstd::basic_format_string
as prvalue where copy elision is guaranteed.
auto runtime_fmt= std::runtime_format("{}"); auto s0=std::format(runtime_fmt,1);// errorauto s1=std::format(std::move(runtime_fmt),1);// still errorauto s2=std::format(std::runtime_format("{}"),1);// ok
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_format | 202311L | (C++26) | Runtime format strings |
#include <format>#include <print>#include <string>#include <string_view> int main(){std::print("Hello {}!\n","world"); std::string fmt;for(int i{}; i!=3;++i){ fmt+="{} ";// constructs the formatting stringstd::print("{} : ", fmt);std::println(std::runtime_format(fmt),"alpha",'Z',3.14,"unused");}}
Output:
Hello world!{} : alpha{} {} : alpha Z{} {} {} : alpha Z 3.14
(C++20) | stores formatted representation of the arguments in a new string (function template)[edit] |
(C++20) | non-template variant ofstd::format using type-erased argument representation (function)[edit] |
(C++20)(C++20)(C++20) | class template that performs compile-time format string checks at construction time (class template)[edit] |