std::enable...optimization(3)
π 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:
Tis one of the types wherestd::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 typeconst 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 asstd::printexcept 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms