| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Standard format specification | ||||
| Formatting functions | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
| Format strings | ||||
(C++20)(C++20)(C++20) | ||||
(C++26) | ||||
| Formatting concepts | ||||
(C++23) | ||||
| Formatter | ||||
(C++20) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++23) | ||||
format_kind (C++23) | ||||
| Formatting arguments | ||||
(C++20) | ||||
(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(deprecated in C++26) | ||||
(C++20)(C++20) | ||||
| Format error | ||||
(C++20) |
Defined in header <format> | ||
template<class R> constexpr/* unspecified */ format_kind=/* unspecified */; | (1) | (since C++23) |
template<ranges::input_range R> requiresstd::same_as<R,std::remove_cvref_t<R>> | (2) | (since C++23) |
The variable templateformat_kind selects an appropriatestd::range_format for a rangeR.
std::format_kind<R> is defined as follows:
R::key_type is valid and denotes a type:R::mapped_type is valid and denotes a type, letU bestd::remove_cvref_t<ranges::range_reference_t<R>>.U is a specialization ofstd::pair orU is a specialization ofstd::tuple andstd::tuple_size_v<U>==2,std::format_kind<R> isstd::range_format::map.A program that instantiates the primary template of theformat_kind variable template is ill-formed.
Given a cv-unqualifiedprogram-defined typeT that modelsinput_range, a program can specializeformat_kind forT. Such specializations are usable in constant expressions, and have typeconststd::range_format.
namespace detail{template<typename>constexprbool is_pair_or_tuple_2=false; template<typename T,typename U>constexprbool is_pair_or_tuple_2<std::pair<T, U>>=true; template<typename T,typename U>constexprbool is_pair_or_tuple_2<std::tuple<T, U>>=true; template<typename T> requiresstd::is_reference_v<T>||std::is_const_v<T>constexprbool is_pair_or_tuple_2<T>= is_pair_or_tuple_2<std::remove_cvref_t<T>>;} template<class R>constexpr range_format format_kind=[]{ static_assert(false,"instantiating a primary template is not allowed");return range_format::disabled;}(); template<ranges::input_range R> requiresstd::same_as<R,std::remove_cvref_t<R>>constexpr range_format format_kind<R>=[]{ifconstexpr(std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<R>>, R>)return range_format::disabled;elseifconstexpr(requires{typename R::key_type;}){ifconstexpr(requires{typename R::mapped_type;}&& detail::is_pair_or_tuple_2<std::ranges::range_reference_t<R>>)return range_format::map;elsereturn range_format::set;}elsereturn range_format::sequence;}(); |
#include <filesystem>#include <format>#include <map>#include <set>#include <vector> struct A{}; static_assert(std::format_kind<std::vector<int>>== std::range_format::sequence);static_assert(std::format_kind<std::map<int,int>>== std::range_format::map);static_assert(std::format_kind<std::set<int>>== std::range_format::set);static_assert(std::format_kind<std::filesystem::path>== std::range_format::disabled);// ill-formed:// static_assert(std::format_kind<A> == std::range_format::disabled); int main(){}
(C++23) | specifies how a range should be formatted (enum)[edit] |