Namespaces
Variants
Views
Actions

std::basic_format_arg

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)
Formatting arguments
basic_format_arg
(C++20)
Format error
 
Defined in header <format>
template<class Context>
class basic_format_arg;
(since C++20)

Provides access to a formatting argument.

basic_format_arg objects are typically created by std::make_format_args and accessed through std::visit_format_arg.

A basic_format_arg object behaves as if it stores a std::variant of the following types:

  • std::monostate (only if the object was default-constructed)
  • bool
  • Context::char_type
  • int
  • unsigned int
  • long long int
  • unsigned long long int
  • float
  • double
  • long double
  • const Context::char_type*
  • std::basic_string_view<Context::char_type>
  • const void*
  • basic_format_arg::handle

Contents

[edit] Member classes

Type Definition
handle
type-erased wrapper that allows formatting an object of user-defined type
(class)

[edit] Member functions

(constructor)
constructs a std::basic_format_arg
(public member function)
operator bool
checks if the current object holds a formatting argument
(public member function)

[edit] Non-member functions

argument visitation interface for user-defined formatters
(function template) [edit]

std::basic_format_arg::handle

template<class Context>
class basic_format_arg<Context>::handle;

Allows formatting an object of a user-defined type.

Member functions

format
formats the referenced object with the given contexts
(public member function)

std::basic_format_arg::handle::format

void format(std::basic_format_parse_context<Context::char_type>& parse_ctx,
            Context& format_ctx) const;

Let T be the type of the associated formatting argument, ref be a const T& that refers to the formatting argument. Equivalent to:

typename Context::template formatter_type<T> f;
parse_ctx.advance_to(f.parse(parse_ctx));
format_ctx.advance_to(f.format(ref, format_ctx));

std::basic_format_arg::basic_format_arg

basic_format_arg() noexcept;

Default constructor. Constructs a basic_format_arg that does not hold a formatting argument. The stored object has type std::monostate.

To create a basic_format_arg that holds a formatting argument, std::make_format_args has to be used.

std::basic_format_arg::operator bool

explicit operator bool() const noexcept;

Checks whether *this holds a formatting argument.

Returns true if *this holds a formatting argument (i.e. the stored object does not have type std::monostate), false otherwise.

[edit] Example

[edit] See also