std::formattable(3)

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

πŸ’– std::formattable(3) πŸ’–

okay bestie, welcome to the std::formattable(3) page from the C++ Standard Libary manual β€” yes, that’s the manual name, and we’re not fixing the spelling, we’re just living with it πŸ’…. This page is short but every detail matters, so let’s get into it.


πŸŽ€ NAME πŸŽ€

std::formattable β€” literally std::formattable. That’s the name, periodt.


✨ Synopsis ✨

Defined in header <format>.

template< class T, class CharT >

concept formattable = /* formattable_with */<
  std::remove_reference_t<T>,                                 (1)
(since C++23)
  std::basic_format_context</* fmt_iter_for */<CharT>, CharT>

>;
Helper templates
template< class CharT >                                       (2)
(exposition only*)
using /* fmt_iter_for */ = /* unspecified */;
template< class T, class Context,

          class Formatter =
              typename Context::template
                  formatter_type<std::remove_const_t<T>> >
concept /* formattable_with */ =
  std::semiregular<Formatter> &&
  requires (Formatter& f, const Formatter& cf, T&& t, Context
fc,                                                           (3)
(exposition only*)
            std::basic_format_parse_context<
                typename Context::char_type
            > pc) {
    { f.parse(pc) } -> std::same_as<typename
decltype(pc)::iterator>;
    { cf.format(t, fc) } -> std::same_as<typename
Context::iterator>;

  };

okay so here’s the tea β˜•: the concept formattable specifies that std::formatter<std::remove_cvref_t<T>, CharT> meets the requirements of BasicFormatter and Formatter (if std::remove_reference_t<T> is const-qualified).

and the exposition-only alias template /* fmt_iter_for */ yields an unspecified type that satisfies std::output_iterator<const CharT&>.

exposition-only means exposition-only, bestie β€” that’s literally what the page says, so don’t go treating those bits like public API lore 🫢

πŸ’€ Defect reports πŸ’€

the committee pulled up with receipts: the following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • LWG 3925 β€” applied to C++23. Behavior as published: β€œthe second template argument of std::basic_format_context was not provided”. Correct behavior: β€œprovided”.

πŸ¦‹ See also πŸ¦‹

  • formatter (C++20) β€” defines formatting rules for a given type (class template).
  • BasicFormatter (C++20) β€” abstracts formatting operations for a given formatting argument type and character type (named requirement).
  • Formatter (C++20) β€” defines functions used by the formatting library (named requirement).

source/version + date check, bestie: http://cppreference.com, 2024.06.10 β€” that’s the footer vibes, and we are so done here. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from