std::basic_format_context(3)
π std::basic_format_context(3) π
πΈ NAME πΈ
std::basic_format_context β std::basic_format_context
okay bestie, we're in the C++ Standard Libary manual, page std::basic_format_context(3). Buckle up, because this one is all about formatting state access. π
β¨ Synopsis β¨
Defined in header <format>
template< class OutputIt, class CharT >
(1) (since C++20)
class basic_format_context;
using format_context = std::basic_format_context</* unspecified */,
(2) (since C++20)
char>;
using wformat_context = std::basic_format_context</* unspecified */,
(3) (since C++20)
wchar_t>;
okay so what is this vibe? It provides access to formatting state consisting of the formatting arguments and the output iterator. β¨
- 2) The unspecified template argument is an output iterator that appends to
std::string, such asstd::back_insert_iterator<std::string>. Implementations typically use an iterator to type-erased buffer type that supports appending to any contiguous and resizable container. - 3) The unspecified template argument is an output iterator that appends to
std::wstring.
The behavior is undefined ifOutputItdoes not modelstd::output_iterator<const CharT&>. Like, actually undefined β do not play with that. π
A program that declares an explicit or partial specialization of std::basic_format_context is ill-formed, no diagnostic required. So if you're thinking about specializing it: don't, bestie. π
𧬠Member types π§¬
iteratorβOutputItchar_typeβCharT
π Member alias templates π
formatter_type<T>βstd::formatter<T, CharT>
π οΈ Member functions π οΈ
argβ returns the argument at the given index (public member function)localeβ returns the locale used for locale-specific formatting (public member function)outβ returns the iterator to output buffer (public member function)advance_toβ advances the output iterator to the given position (public member function)
π·οΈ std::basic_format_context::arg
std::basic_format_arg<basic_format_context> arg( std::size_t id )
const;
Returns a std::basic_format_arg holding the id-th argument in args, where args is the parameter pack or std::basic_format_args object passed to the formatting function. π«Ά
If id is not less than the number of formatting arguments, returns a default-constructed std::basic_format_arg (holding a std::monostate object). No index, no argument, no drama. π
π std::basic_format_context::locale
std::locale locale();
Returns the locale passed to the formatting function, or a default-constructed std::locale if the formatting function does not take a locale. Locale-specific formatting said slay. π
π¦ std::basic_format_context::out
iterator out();
Returns the iterator to the output buffer. The result is move-constructed from the stored iterator. Subtle but important, iykyk. β¨
π₯ std::basic_format_context::advance_to
void advance_to( iterator it );
Move assigns it to the stored output iterator. After a call to advance_to, the next call to out() will return an iterator with the value that it had before the assignment. That's the whole plot twist. π
π§ͺ Example
This section is incomplete.
Reason: no example.
π©Ή Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. π§
- LWG 3567, applied to C++20 β behavior as published:
basic_format_contextdoes not work move-only iterator types; correct behavior: made to move iterators. - LWG 3975, applied to C++20 β behavior as published: user specialization of
basic_format_contextwas allowed; correct behavior: disallowed.
π Category
- Todo no example
shoutout to http://cppreference.com, 2024.06.10, and this page is literally std::basic_format_context(3). bye bestie, go format something iconic π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms