Namespaces
Variants
Views
Actions

std::basic_format_context

From cppreference.com
< cpp‎ | utility‎ | format
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Formatting library
Formatting functions
(C++20)
(C++20)
(C++20)
(C++20)
Formatter
(C++20)
basic_format_contextformat_contextwformat_context
(C++20)(C++20)(C++20)
Formatting arguments
Format error
 
Defined in header <format>
template<class OutputIt, class CharT>
class basic_format_context;
(1) (since C++20)
using format_context = basic_format_context</* unspecified */, char>;
(2) (since C++20)
using wformat_context = basic_format_context</* unspecified */, wchar_t>;
(3) (since C++20)

Provides access to formatting state consisting of the formatting arguments and the output iterator.

The behavior is undefined if OutputIt does not model std::output_iterator<const CharT&>.

2) The unspecified template argument is an output iterator that appends to std::string, such as std::back_insert_iterator<std::string>. Implementations are encouraged to 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.

Contents

[edit] Member types

Type Definition
iterator OutputIt
char_type CharT

[edit] Member alias templates

Type Definition
formatter_type<T> std::formatter<T, CharT>

[edit] 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).

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.

std::basic_format_context::out

iterator out();

Returns the iterator to the output buffer.

std::basic_format_context::advance_to

void advance_to(iterator it);

Sets the output iterator to it. After a call to advance_to, subsequent calls to out() will return a copy of it.

[edit] Example

[edit] See also