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 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
11 | |
12 | // <vector> |
13 | |
14 | // template<class T, class charT> |
15 | // requires is-vector-bool-reference<T> |
16 | // struct formatter<T, charT> |
17 | |
18 | // template<class FormatContext> |
19 | // typename FormatContext::iterator |
20 | // format(const T& r, FormatContext& ctx) const; |
21 | |
22 | // Note this tests the basics of this function. It's tested in more detail in |
23 | // the format functions test. |
24 | |
25 | #include <cassert> |
26 | #include <concepts> |
27 | #include <format> |
28 | #include <iterator> |
29 | #include <vector> |
30 | |
31 | #include "test_format_context.h" |
32 | #include "test_macros.h" |
33 | #include "make_string.h" |
34 | |
35 | #define SV(S) MAKE_STRING_VIEW(CharT, S) |
36 | |
37 | template <class StringViewT> |
38 | void test_format(StringViewT expected, std::vector<bool>::reference arg) { |
39 | using CharT = typename StringViewT::value_type; |
40 | using String = std::basic_string<CharT>; |
41 | using OutIt = std::back_insert_iterator<String>; |
42 | using FormatCtxT = std::basic_format_context<OutIt, CharT>; |
43 | |
44 | const std::formatter<std::vector<bool>::reference, CharT> formatter; |
45 | |
46 | String result; |
47 | OutIt out = std::back_inserter(result); |
48 | FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>(arg)); |
49 | formatter.format(arg, format_ctx); |
50 | assert(result == expected); |
51 | } |
52 | |
53 | template <class CharT> |
54 | void test_fmt() { |
55 | test_format(SV("true" ), std::vector<bool>{true}[0]); |
56 | test_format(SV("false" ), std::vector<bool>{false}[0]); |
57 | } |
58 | |
59 | void test() { |
60 | test_fmt<char>(); |
61 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
62 | test_fmt<wchar_t>(); |
63 | #endif |
64 | } |
65 | |
66 | int main(int, char**) { |
67 | test(); |
68 | |
69 | return 0; |
70 | } |
71 | |