Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_format_arg

      From cppreference.com
      <cpp‎ |utility‎ |format
       
       
       
      Formatting library
      Standard format specification
      Formatting functions
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      Format strings
      Formatting concepts
      Formatter
      (C++20)
      Formatting arguments
      basic_format_arg
      (C++20)
      (C++20)(deprecated in C++26)
      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 bystd::make_format_args and accessed throughstd::visit_format_arg or thevisit member functions(since C++26).

      Abasic_format_arg object behaves as if it contains astd::variant of the following types:

      • std::monostate (only if the object was default-constructed)
      • bool
      • Context::char_type
      • int
      • unsignedint
      • longlongint
      • unsignedlonglongint
      • float
      • double
      • longdouble
      • const Context::char_type*
      • std::basic_string_view<Context::char_type>
      • constvoid*
      • basic_format_arg::handle

      Contents

      [edit]Member classes

      (C++20)
      type-erased wrapper that allows formatting an object of user-defined type
      (public member class)

      [edit]Member functions

      (constructor)
      (C++20)
      constructs astd::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 contained formatting argument
      (public member function)

      [edit]Non-member functions

      (C++20)(deprecated in C++26)
      argument visitation interface for user-defined formatters
      (function template)[edit]

      std::basic_format_arg::basic_format_arg

      basic_format_arg()noexcept;
      (since C++20)

      Default constructor. Constructs abasic_format_arg that does not hold a formatting argument. The contained object has typestd::monostate.

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

      std::basic_format_arg::operator bool

      explicit operatorbool()constnoexcept;
      (since C++20)

      Checks whether*this holds a formatting argument.

      Returnstrue if*this holds a formatting argument (i.e. the contained object does not have typestd::monostate),false otherwise.

      std::basic_format_arg::visit

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

      Applies the visitorvis to the object contained inarg.

      Thevisit functions do not modify thebasic_format_arg object on which it is called because a copy of the object is used when callingvis.

      1) Equivalent toreturnstd::visit(std::forward<Visitor>(vis), v);, wherev is thestd::variant contained inarg.
      2) Equivalent toreturnstd::visit<R>(std::forward<Visitor>(vis), v);, wherev is thestd::variant contained inarg.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_format202306L(C++26)Membervisit

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      class that provides access to all formatting arguments
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/format/basic_format_arg&oldid=183337"

      [8]ページ先頭

      ©2009-2025 Movatter.jp