On this page
std::format_kind
Defined in header <format> |
||
---|---|---|
|
(1) | (since C++23) |
|
(2) | (since C++23) |
The variable template format_kind
selects an appropriate std::range_format
for a range R
.
format_kind<R>
is defined as follows:
- If
std::same_as<std::remove_cvref_t<ranges::range_reference_t<R>>, R>
is true,format_kind<R>
isrange_format::disabled
. - Otherwise, if
R::key_type
is valid and denotes a type:- If
R::mapped_type
is valid and denotes a type, letU
bestd::remove_cvref_t<ranges::range_reference_t<R>>
. If eitherU
is a specialization ofstd::pair
orU
is a specialization ofstd::tuple
andstd::tuple_size_v<U> == 2
,format_kind<R>
isrange_format::map
. - Otherwise,
format_kind<R>
isrange_format::set
.
- If
- Otherwise,
format_kind<R>
isrange_format::sequence
.
A program that instantiates a primary template of the format_kind
variable template is ill-formed.
User-provided specialization of format_kind
is allowed as long as:
R
is cv-unqualified program-defined type,R
satisfiesinput_range
,- its specialization shall be usable in constant expressions, and
format_kind<R>
has typeconst 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) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/format/format_kind