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