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
69static_assert(std::semiregular<std::formatter<char, char>>);
70
71static_assert(std::semiregular<std::formatter<char*, char>>);
72static_assert(std::semiregular<std::formatter<const char*, char>>);
73static_assert(std::semiregular<std::formatter<char[1], char>>);
74static_assert(std::semiregular<std::formatter<std::string, char>>);
75static_assert(std::semiregular<std::formatter<std::string_view, char>>);
76
77static_assert(std::semiregular<std::formatter<bool, char>>);
78
79static_assert(std::semiregular<std::formatter<signed char, char>>);
80static_assert(std::semiregular<std::formatter<signed short, char>>);
81static_assert(std::semiregular<std::formatter<signed int, char>>);
82static_assert(std::semiregular<std::formatter<signed long, char>>);
83static_assert(std::semiregular<std::formatter<signed long long, char>>);
84
85static_assert(std::semiregular<std::formatter<unsigned char, char>>);
86static_assert(std::semiregular<std::formatter<unsigned short, char>>);
87static_assert(std::semiregular<std::formatter<unsigned int, char>>);
88static_assert(std::semiregular<std::formatter<unsigned long, char>>);
89static_assert(std::semiregular<std::formatter<unsigned long long, char>>);
90
91static_assert(std::semiregular<std::formatter<float, char>>);
92static_assert(std::semiregular<std::formatter<double, char>>);
93static_assert(std::semiregular<std::formatter<long double, char>>);
94
95static_assert(std::semiregular<std::formatter<std::nullptr_t, char>>);
96static_assert(std::semiregular<std::formatter<void*, char>>);
97static_assert(std::semiregular<std::formatter<const void*, char>>);
98
99#if TEST_STD_VER > 20
100static_assert(std::semiregular<std::range_formatter<int, char>>);
101static_assert(std::semiregular<std::formatter<std::tuple<int>, char>>);
102static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, char>>);
103#endif
104
105#ifndef TEST_HAS_NO_WIDE_CHARACTERS
106static_assert(std::semiregular<std::formatter<char, wchar_t>>);
107static_assert(std::semiregular<std::formatter<wchar_t, wchar_t>>);
108
109static_assert(std::semiregular<std::formatter<wchar_t*, wchar_t>>);
110static_assert(std::semiregular<std::formatter<const wchar_t*, wchar_t>>);
111static_assert(std::semiregular<std::formatter<wchar_t[1], wchar_t>>);
112static_assert(std::semiregular<std::formatter<std::wstring, wchar_t>>);
113static_assert(std::semiregular<std::formatter<std::wstring_view, wchar_t>>);
114
115static_assert(std::semiregular<std::formatter<bool, wchar_t>>);
116
117static_assert(std::semiregular<std::formatter<signed char, wchar_t>>);
118static_assert(std::semiregular<std::formatter<signed short, wchar_t>>);
119static_assert(std::semiregular<std::formatter<signed int, wchar_t>>);
120static_assert(std::semiregular<std::formatter<signed long, wchar_t>>);
121static_assert(std::semiregular<std::formatter<signed long long, wchar_t>>);
122
123static_assert(std::semiregular<std::formatter<unsigned char, wchar_t>>);
124static_assert(std::semiregular<std::formatter<unsigned short, wchar_t>>);
125static_assert(std::semiregular<std::formatter<unsigned int, wchar_t>>);
126static_assert(std::semiregular<std::formatter<unsigned long, wchar_t>>);
127static_assert(std::semiregular<std::formatter<unsigned long long, wchar_t>>);
128
129static_assert(std::semiregular<std::formatter<float, wchar_t>>);
130static_assert(std::semiregular<std::formatter<double, wchar_t>>);
131static_assert(std::semiregular<std::formatter<long double, wchar_t>>);
132
133static_assert(std::semiregular<std::formatter<std::nullptr_t, wchar_t>>);
134static_assert(std::semiregular<std::formatter<void*, wchar_t>>);
135static_assert(std::semiregular<std::formatter<const void*, wchar_t>>);
136
137# if TEST_STD_VER > 20
138static_assert(std::semiregular<std::range_formatter<int, wchar_t>>);
139static_assert(std::semiregular<std::formatter<std::tuple<int>, wchar_t>>);
140static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, wchar_t>>);
141# endif
142#endif // TEST_HAS_NO_WIDE_CHARACTERS
143

source code of libcxx/test/std/utilities/format/types.compile.pass.cpp