From cppreference.com
template<classContext>classbasic_format_arg;(since C++20)Provides access to a formatting argument.
basic_format_arg objects are typically created by
and accessed through
or the visit member functions(since C++26).
A basic_format_arg object behaves as if it stores a
of the following types:
std::monostate (only if the object was default-constructed)
bool
Context::char_type
int
unsignedint
longlongint
unsignedlonglongint
float
double
longdouble
constContext::char_type*
std::basic_string_view<Context::char_type>
constvoid*
basic_format_arg::handle
Member classes
(C++20)
type-erased wrapper that allows formatting an object of user-defined type
(public member class)Member functions
(constructor)
(C++20)
constructs a std::basic_format_arg
(public member function)operator bool
(C++20)
checks if the current object holds a formatting argument
(public member function)visit
(C++26)
visit the stored formatting argument
(public member function)Non-member functions
(C++20)(deprecated in C++26)
argument visitation interface for user-defined formatters
(function template)
std::basic_format_arg::basic_format_arg
basic_format_arg()noexcept;(since C++20)Default constructor. Constructs a basic_format_arg that does not hold a formatting argument. The stored object has type
.
To create a basic_format_arg that holds a formatting argument,
has to be used.
std::basic_format_arg::operator bool
explicitoperatorbool()constnoexcept;(since C++20)Checks whether *this holds a formatting argument.
Returns true if *this holds a formatting argument (i.e. the stored object does not have type
), false otherwise.
std::basic_format_arg::visit
template<classVisitor>decltype(auto)visit(thisbasic_format_argarg,Visitor&&vis); (1) (since C++26)template<classR,classVisitor>Rvisit(thisbasic_format_argarg,Visitor&&vis); (2) (since C++26)Applies the visitor vis to the object contained in arg.
The visit functions do not modify the basic_format_arg object on which it is called because a copy of the object is used when calling vis.
1) Equivalent to returnstd::visit(std::forward<Visitor>(vis),v);, where v is the
stored in arg.
2) Equivalent to returnstd::visit<R>(std::forward<Visitor>(vis),v);, where v is the
stored in arg.
Notes
macro ValueStdFeature
(C++26)Member
Example
See also