Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_format_arg<Context>::handle

      From cppreference.com
      <cpp‎ |utility‎ |format‎ |basic format arg
       
       
       
      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::handle
      (C++20)
      (C++20)(deprecated in C++26)
      Format error
       
      Defined in header<format>
      template<class Context>
      class basic_format_arg<Context>::handle;
      (since C++20)

      A type-erased wrapper that allows formatting an object of a user-defined type.

      handle objects are typically created bystd::make_format_args and accessed throughstd::visit_format_arg or thevisit member functions ofstd::basic_format_arg(since C++26).

      Contents

      [edit]Data members

      A typical implementation ofhandle isTriviallyCopyable and only stores two non-static data members:

      • aconstvoid* pointer to the object to be formatted, and
      • avoid(*)(std::basic_format_parse_context<Context::char_type>&, Context&,constvoid*) function pointer to the function performing needed operations in theformat member function (see below).

      [edit]Member functions

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

      std::basic_format_arg<Context>::handle::format

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

      Let

      • T be the type of the formatting argument,
      • TD bestd::remove_const_t<T>,
      • TQ beconst TD ifconst TD satisfies__formattable_with<Context> orTD otherwise, and
      • ref be a reference to the formatting argument.

      Equivalent to:typename Context::template formatter_type<TD> f;
      parse_ctx.advance_to(f.parse(parse_ctx));
      format_ctx.advance_to(f.format(const_cast<TQ&>(static_cast<const TD&>(ref)), format_ctx));

      [edit]Notes

      Ahandle has reference semantics for the formatted argument and does not extend its lifetime. It is the programmer's responsibility to ensure that the argument outlives thehandle. Usually, ahandle is only used within formatting functions.

      [edit]See also

      class template that provides access to a formatting argument for user-defined formatters
      (class template)[edit]
      creates a type-erased object referencing all formatting arguments, convertible toformat_args
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/format/basic_format_arg/handle&oldid=158164"

      [8]ページ先頭

      ©2009-2025 Movatter.jp