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