1 | //===----------------------------------------------------------------------===// |
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | // |
6 | //===----------------------------------------------------------------------===// |
7 | |
8 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
9 | |
10 | // <format> |
11 | |
12 | // C++20 |
13 | // ... provides the following enabled specializations: |
14 | // The debug-enabled specializations |
15 | // template<> struct formatter<char, char>; |
16 | // template<> struct formatter<char, wchar_t>; |
17 | // template<> struct formatter<wchar_t, wchar_t>; |
18 | // |
19 | // For each charT, the debug-enabled string type specializations template<> |
20 | // struct formatter<charT*, charT>; |
21 | // template<> struct formatter<const charT*, charT>; |
22 | // template<size_t N> struct formatter<charT[N], charT>; |
23 | // template<class traits, class Allocator> |
24 | // struct formatter<basic_string<charT, traits, Allocator>, charT>; |
25 | // template<class traits> |
26 | // struct formatter<basic_string_view<charT, traits>, charT>; |
27 | // |
28 | // For each charT, for each cv-unqualified arithmetic type ArithmeticT other |
29 | // than char, wchar_t, char8_t, char16_t, or char32_t, a specialization |
30 | // template<> struct formatter<ArithmeticT, charT>; |
31 | // |
32 | // For each charT, the pointer type specializations template<> struct |
33 | // formatter<nullptr_t, charT>; |
34 | // template<> struct formatter<void*, charT>; |
35 | // template<> struct formatter<const void*, charT>; |
36 | |
37 | // C++23 |
38 | // [format.range.formatter] |
39 | // template<class T, class charT = char> |
40 | // requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> |
41 | // class range_formatter; |
42 | // |
43 | // [format.tuple]/1 |
44 | // For each of pair and tuple, the library provides the following formatter |
45 | // specialization where pair-or-tuple is the name of the template: |
46 | // template<class charT, formattable<charT>... Ts> |
47 | // struct formatter<pair-or-tuple<Ts...>, charT> { |
48 | |
49 | // [format.formatter.spec]/4 |
50 | // If the library provides an explicit or partial specialization of |
51 | // formatter<T, charT>, that specialization is enabled and meets the |
52 | // Formatter requirements except as noted otherwise. |
53 | // |
54 | // Test parts of the BasicFormatter requirements. Like the formattable concept |
55 | // it uses the semiregular concept. This test does not use the formattable |
56 | // concept since the intent is for the formatter to be available without |
57 | // including the <format> header. |
58 | |
59 | #include <concepts> |
60 | #include <cstddef> |
61 | #include <format> |
62 | #include <string_view> |
63 | #include <string> |
64 | #include <tuple> |
65 | #include <utility> |
66 | |
67 | #include "test_macros.h" |
68 | |
69 | static_assert(std::semiregular<std::formatter<char, char>>); |
70 | |
71 | static_assert(std::semiregular<std::formatter<char*, char>>); |
72 | static_assert(std::semiregular<std::formatter<const char*, char>>); |
73 | static_assert(std::semiregular<std::formatter<char[1], char>>); |
74 | static_assert(std::semiregular<std::formatter<std::string, char>>); |
75 | static_assert(std::semiregular<std::formatter<std::string_view, char>>); |
76 | |
77 | static_assert(std::semiregular<std::formatter<bool, char>>); |
78 | |
79 | static_assert(std::semiregular<std::formatter<signed char, char>>); |
80 | static_assert(std::semiregular<std::formatter<signed short, char>>); |
81 | static_assert(std::semiregular<std::formatter<signed int, char>>); |
82 | static_assert(std::semiregular<std::formatter<signed long, char>>); |
83 | static_assert(std::semiregular<std::formatter<signed long long, char>>); |
84 | |
85 | static_assert(std::semiregular<std::formatter<unsigned char, char>>); |
86 | static_assert(std::semiregular<std::formatter<unsigned short, char>>); |
87 | static_assert(std::semiregular<std::formatter<unsigned int, char>>); |
88 | static_assert(std::semiregular<std::formatter<unsigned long, char>>); |
89 | static_assert(std::semiregular<std::formatter<unsigned long long, char>>); |
90 | |
91 | static_assert(std::semiregular<std::formatter<float, char>>); |
92 | static_assert(std::semiregular<std::formatter<double, char>>); |
93 | static_assert(std::semiregular<std::formatter<long double, char>>); |
94 | |
95 | static_assert(std::semiregular<std::formatter<std::nullptr_t, char>>); |
96 | static_assert(std::semiregular<std::formatter<void*, char>>); |
97 | static_assert(std::semiregular<std::formatter<const void*, char>>); |
98 | |
99 | #if TEST_STD_VER > 20 |
100 | static_assert(std::semiregular<std::range_formatter<int, char>>); |
101 | static_assert(std::semiregular<std::formatter<std::tuple<int>, char>>); |
102 | static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, char>>); |
103 | #endif |
104 | |
105 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
106 | static_assert(std::semiregular<std::formatter<char, wchar_t>>); |
107 | static_assert(std::semiregular<std::formatter<wchar_t, wchar_t>>); |
108 | |
109 | static_assert(std::semiregular<std::formatter<wchar_t*, wchar_t>>); |
110 | static_assert(std::semiregular<std::formatter<const wchar_t*, wchar_t>>); |
111 | static_assert(std::semiregular<std::formatter<wchar_t[1], wchar_t>>); |
112 | static_assert(std::semiregular<std::formatter<std::wstring, wchar_t>>); |
113 | static_assert(std::semiregular<std::formatter<std::wstring_view, wchar_t>>); |
114 | |
115 | static_assert(std::semiregular<std::formatter<bool, wchar_t>>); |
116 | |
117 | static_assert(std::semiregular<std::formatter<signed char, wchar_t>>); |
118 | static_assert(std::semiregular<std::formatter<signed short, wchar_t>>); |
119 | static_assert(std::semiregular<std::formatter<signed int, wchar_t>>); |
120 | static_assert(std::semiregular<std::formatter<signed long, wchar_t>>); |
121 | static_assert(std::semiregular<std::formatter<signed long long, wchar_t>>); |
122 | |
123 | static_assert(std::semiregular<std::formatter<unsigned char, wchar_t>>); |
124 | static_assert(std::semiregular<std::formatter<unsigned short, wchar_t>>); |
125 | static_assert(std::semiregular<std::formatter<unsigned int, wchar_t>>); |
126 | static_assert(std::semiregular<std::formatter<unsigned long, wchar_t>>); |
127 | static_assert(std::semiregular<std::formatter<unsigned long long, wchar_t>>); |
128 | |
129 | static_assert(std::semiregular<std::formatter<float, wchar_t>>); |
130 | static_assert(std::semiregular<std::formatter<double, wchar_t>>); |
131 | static_assert(std::semiregular<std::formatter<long double, wchar_t>>); |
132 | |
133 | static_assert(std::semiregular<std::formatter<std::nullptr_t, wchar_t>>); |
134 | static_assert(std::semiregular<std::formatter<void*, wchar_t>>); |
135 | static_assert(std::semiregular<std::formatter<const void*, wchar_t>>); |
136 | |
137 | # if TEST_STD_VER > 20 |
138 | static_assert(std::semiregular<std::range_formatter<int, wchar_t>>); |
139 | static_assert(std::semiregular<std::formatter<std::tuple<int>, wchar_t>>); |
140 | static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, wchar_t>>); |
141 | # endif |
142 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
143 | |