std::basic_format_arg(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

std::basic_format_arg β€” std::basic_format_arg

Welcome to std::basic_format_arg(3), the page from the C++ Standard Libary manual β€” yes, β€œLibary” is literally what the header says, not me πŸ’€. We are gonna get you comfy with formatting arguments, no cap, bestie πŸ’….


✨ Synopsis ✨

Defined in header <format>.

template< class Context >   (since C++20)
class basic_format_arg;

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 or the visit member functions (since C++26).

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

πŸŽ€ Member classes πŸŽ€

  • handle β€” type-erased wrapper that allows formatting an object of user-defined type; (C++20); (public member class)

🫢 Member functions 🫢

  • constructor β€” constructs a std::basic_format_arg; (C++20); (public member function)
  • operator bool β€” checks if the current object holds a formatting argument; (C++20); (public member function)
  • visit β€” visit the stored formatting argument; (C++26); (public member function)

🌈 Non-member functions 🌈

  • visit_format_arg β€” argument visitation interface for user-defined formatters; (C++20); (deprecated in C++26); (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 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;  (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 std::monostate), false otherwise.

⭐ std::basic_format_arg::visit ⭐

  1. template< class Visitor > (since C++26):
decltype(auto) visit( this basic_format_arg arg, Visitor&& vis );
  1. template< class R, class Visitor > (since C++26):
R visit( this basic_format_arg arg, Visitor&& vis );

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 return std::visit(std::forward<Visitor>(vis), v);, where v is the std::variant stored in arg.
  2. Equivalent to return std::visit<R>(std::forward<Visitor>(vis), v);, where v is the std::variant stored in arg.

🌸 Notes 🌸

πŸ“ Feature-test macro πŸ“

  • __cpp_lib_format β€” value 202306L; Std (C++26); Feature Member visit

🌟 Example 🌟

This section is incomplete Reason: no example

πŸ‘‘ See also πŸ‘‘

  • basic_format_args β€” (C++20)
  • format_args β€” (C++20)
  • wformat_args β€” (C++20); (class template); class that provides access to all formatting arguments

πŸŽ€ Category πŸŽ€

  • Todo no example

Mwah πŸ’‹ β€” source http://cppreference.com, version/date 2024.06.10, page std::basic_format_arg(3). Slay your formatting era, bestie 🫢✨

πŸ“¦ where this page comes from