std::enable...optimization(3)

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

πŸ’… NAME πŸ’…

std::enable_nonlocking_formatter_optimization β€” yes bestie it's the same name twice, that's just how cppreference do πŸŽ€


✨ SYNOPSIS ✨

Okay so first things first, it lives right here:

Defined in header <format>
template< class T >
constexpr bool enable_nonlocking_formatter_optimization = false;

(since C++23) πŸ¦‹

This template is literally a little bool flag that implementations can use to turn on efficient implementations of std::print and std::println. That's the whole vibe.

So here's the tea: if std::enable_nonlocking_formatter_optimization<T> is true, then printing an argument of type T can be done in a more efficient way (peep std::print for the details πŸ‘€).

And std::enable_nonlocking_formatter_optimization specializations are allowed to be true in these cases:

  • T is one of the types where std::format<T, CharT> is a basic standard specialization (full list below, don't worry 🌸).
  • A program may specialize this template for any cv-unqualified program-defined type T. Those specializations must be usable in constant expressions and have type const bool β€” no cap, that's a hard requirement πŸ’€

πŸŽ€ Basic standard specializations πŸŽ€

In the following list, CharT is either char or wchar_t, and ArithmeticT is any cv-unqualified arithmetic type other than char, wchar_t, char8_t, char16_t, or char32_t. Iconic narrowing, honestly πŸ‘‘

πŸ“ Nonlocking flag for character formatters

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<CharT> = true;

That one's (1) if you're keeping score πŸ“

🌈 Nonlocking flag for string formatters

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<CharT*> = true;

(2) ✨

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<const CharT*> = true;

(3) ✨

template< std::size_t N >
inline constexpr bool enable_nonlocking_formatter_optimization<CharT[N]> = true;

(4) ✨

template< class Traits, class Alloc >
inline constexpr bool enable_nonlocking_formatter_optimization
    <std::basic_string<CharT, Traits, Alloc>> = true;

(5) ✨

template< class Traits >
inline constexpr bool enable_nonlocking_formatter_optimization
    <std::basic_string_view<CharT, Traits>> = true;

(6) ✨

πŸ’œ Nonlocking flag for arithmetic formatters

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<ArithmeticT> = true;

(7) ✨

πŸ¦‹ Nonlocking flag for pointer formatters

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<std::nullptr_t> = true;

(8) ✨

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<void*> = true;

(9) ✨

template<>
inline constexpr bool enable_nonlocking_formatter_optimization<const void*> = true;

(10) ✨ and that's the whole set, periodt πŸ’…


πŸ‘‘ See also πŸ‘‘

  • formatter β€” defines formatting rules for a given type (C++20) (class template) 🧚
  • print β€” prints to stdout or a file stream using formatted representation of the arguments (C++23) (function template) 🫢
  • println β€” same as std::print except that each print is terminated by additional new line (C++23) (function template) 🌸

ngl this whole page is basically one bool and ten specializations, but she ate and left no crumbs πŸ’€πŸ”₯

okay bestie that's the whole page, mwah πŸ’– this one's from http://cppreference.com, dated 2024.06.10, and it's literally titled std::enable...optimization(3) β€” go forth and format efficiently 🌟

πŸ“¦ where this page comes from