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, c++20 |
10 | |
11 | // <format> |
12 | |
13 | // template<class T, class charT> |
14 | // concept formattable = ... |
15 | |
16 | #include <concepts> |
17 | #include <format> |
18 | |
19 | #include "test_macros.h" |
20 | |
21 | template <class T, class CharT> |
22 | void assert_is_not_formattable() { |
23 | static_assert(!std::formattable<T, CharT>); |
24 | } |
25 | |
26 | template <class T, class CharT> |
27 | void assert_is_formattable() { |
28 | // Only formatters for CharT == char || CharT == wchar_t are enabled for the |
29 | // standard formatters. When CharT is a different type the formatter should |
30 | // be disabled. |
31 | if constexpr (std::same_as<CharT, char> |
32 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
33 | || std::same_as<CharT, wchar_t> |
34 | #endif |
35 | ) |
36 | static_assert(std::formattable<T, CharT>); |
37 | else |
38 | assert_is_not_formattable<T, CharT>(); |
39 | } |
40 | |
41 | template <class CharT> |
42 | void test() { |
43 | assert_is_formattable<float, CharT>(); |
44 | assert_is_formattable<double, CharT>(); |
45 | assert_is_formattable<long double, CharT>(); |
46 | } |
47 | |
48 | void test() { |
49 | test<char>(); |
50 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
51 | test<wchar_t>(); |
52 | #endif |
53 | test<char8_t>(); |
54 | test<char16_t>(); |
55 | test<char32_t>(); |
56 | |
57 | test<int>(); |
58 | } |
59 | |