| Defined in header <format>
|
||
| template< class R > constexpr /* unspecified */ format_kind = /* unspecified */; |
(1) | (since C++23) |
| template< ranges::input_range R > requires std::same_as<R, std::remove_cvref_t<R>> constexpr range_format format_kind<R> = /* see description */; |
(2) | (since C++23) |
The variable template format_kind selects an appropriate std::range_format for a range R.
std::format_kind<R> is defined as follows:
- If
std::same_as<std::remove_cvref_t<ranges::range_reference_t<R>>, R>istrue,std::format_kind<R>isstd::range_format::disabled. - Otherwise, if
R::key_typeis valid and denotes a type:- If
R::mapped_typeis valid and denotes a type, letUbestd::remove_cvref_t<ranges::range_reference_t<R>>.
- If
- If either
Uis a specialization of std::pair orUis a specialization of std::tuple andstd::tuple_size_v<U> == 2,std::format_kind<R>isstd::range_format::map.
- Otherwise,
std::format_kind<R>isstd::range_format::set.
- If either
- Otherwise,
std::format_kind<R>isstd::range_format::sequence.
A program that instantiates a primary template of the format_kind variable template is ill-formed.
Given a cv-unqualified program-defined type T that models input_range, a program can specialize format_kind for T. Such specializations are usable in constant expressions, and have type const std::range_format.
Possible implementation
|
Example
#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>> == 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() {}See also
| (C++23) |
specifies how a range should be formatted (enum) |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.