std:: format_kind
|
Défini dans l'en-tête
<format>
|
||
|
template
<
class
R
>
constexpr /* non spécifié */ format_kind = /* non spécifié */ ; |
(1) | (depuis C++23) |
|
template
<
ranges::
input_range
R
>
requiert
std::
same_as
<
R,
std::
remove_cvref_t
<
R
>>
|
(2) | (depuis C++23) |
Le modèle de variable
format_kind
sélectionne un
std::range_format
approprié pour une plage
R
.
std :: format_kind < R > est défini comme suit :
- Si std:: same_as < std:: remove_cvref_t < ranges:: range_reference_t < R >> , R > est true , std :: format_kind < R > est std :: range_format :: disabled .
-
Sinon, si
R::key_typeest valide et désigne un type :-
Si
R::mapped_typeest valide et désigne un type, soitUégal à std:: remove_cvref_t < ranges:: range_reference_t < R >> .
-
Si
-
-
Si soit
Uest une spécialisation de std::pair , soitUest une spécialisation de std::tuple et std:: tuple_size_v < U > == 2 , std :: format_kind < R > est std :: range_format :: map .
- Sinon, std :: format_kind < R > est std :: range_format :: set .
-
Si soit
- Sinon, std :: format_kind < R > est std :: range_format :: sequence .
Un programme qui instancie le modèle principal du
format_kind
est incorrect.
Étant donné un type
défini par le programme
T
non qualifié cv qui modélise
input_range
, un programme peut spécialiser
format_kind
pour
T
. Ces spécialisations sont utilisables dans des expressions constantes, et ont le type
const
std::
range_format
.
Implémentation possible
namespace detail { template< typename > constexpr bool is_pair_or_tuple_2 = false; template< typename T, typename U > constexpr bool is_pair_or_tuple_2<std::pair<T, U>> = true; template< typename T, typename U > constexpr bool is_pair_or_tuple_2<std::tuple<T, U>> = true; template < typename T > requires std::is_reference_v<T> || std::is_const_v<T> constexpr bool 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, "l'instanciation d'un template primaire n'est pas autorisée"); return range_format::disabled; }(); template< ranges::input_range R > requires std::same_as<R, std::remove_cvref_t<R>> constexpr range_format format_kind<R> = [] { if constexpr (std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<R>>, R>) return range_format::disabled; else if constexpr (requires { typename R::key_type; }) { if constexpr (requires { typename R::mapped_type; } && detail::is_pair_or_tuple_2<std::ranges::range_reference_t<R>>) return range_format::map; else return range_format::set; } else return range_format::sequence; }(); |
Exemple
#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); // mal formé : // static_assert(std::format_kind<A> == std::range_format::disabled); int main() {}
Voir aussi
|
(C++23)
|
spécifie comment une plage doit être formatée
(enum) |