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 | // libc++ supports basic_format_string in C++20 as an extension |
12 | // UNSUPPORTED: !stdlib=libc++ && c++20 |
13 | |
14 | // <format> |
15 | |
16 | // template<class charT, class... Args> |
17 | // class basic_format_string<charT, type_identity_t<Args>...> |
18 | // |
19 | // constexpr basic_string_view<charT> get() const noexcept { return str; } |
20 | |
21 | #include <format> |
22 | |
23 | #include <cassert> |
24 | #include <concepts> |
25 | #include <string_view> |
26 | |
27 | #include "test_macros.h" |
28 | #include "make_string.h" |
29 | |
30 | #define CSTR(S) MAKE_CSTRING(CharT, S) |
31 | #define SV(S) MAKE_STRING_VIEW(CharT, S) |
32 | |
33 | template <class CharT> |
34 | constexpr bool test() { |
35 | assert((std::basic_format_string<CharT>{CSTR("foo" )}.get() == SV("foo" ))); |
36 | assert((std::basic_format_string<CharT, int>{CSTR("{}" )}.get() == SV("{}" ))); |
37 | assert((std::basic_format_string<CharT, int, char>{CSTR("{} {:*>6}" )}.get() == SV("{} {:*>6}" ))); |
38 | |
39 | // Embedded NUL character |
40 | assert((std::basic_format_string<CharT, void*, bool>{SV("{}\0{}" )}.get() == SV("{}\0{}" ))); |
41 | return true; |
42 | } |
43 | |
44 | int main(int, char**) { |
45 | test<char>(); |
46 | static_assert(test<char>()); |
47 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
48 | test<wchar_t>(); |
49 | static_assert(test<wchar_t>()); |
50 | #endif |
51 | return 0; |
52 | } |
53 | |