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
6 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
14 // template<class charT, formattable<charT>... Ts>
15 // struct formatter<pair-or-tuple<Ts...>, charT>
17 // template<class ParseContext>
18 // constexpr typename ParseContext::iterator
19 // parse(ParseContext& ctx);
21 // Note this tests the basics of this function. It's tested in more detail in
22 // the format functions tests.
30 #include "test_format_context.h"
31 #include "test_macros.h"
32 #include "make_string.h"
34 #define SV(S) MAKE_STRING_VIEW(CharT, S)
36 template <class Arg
, class StringViewT
>
37 constexpr void test(StringViewT fmt
, std::size_t offset
) {
38 using CharT
= typename
StringViewT::value_type
;
39 auto parse_ctx
= std::basic_format_parse_context
<CharT
>(fmt
);
40 std::formatter
<Arg
, CharT
> formatter
;
41 static_assert(std::semiregular
<decltype(formatter
)>);
43 std::same_as
<typename
StringViewT::iterator
> auto it
= formatter
.parse(parse_ctx
);
44 assert(it
== fmt
.end() - offset
);
47 template <class CharT
, class Arg
>
48 constexpr void test() {
50 test
<Arg
>(SV("42"), 0);
52 test
<Arg
>(SV("}"), 1);
53 test
<Arg
>(SV("42}"), 1);
56 template <class CharT
>
57 constexpr void test() {
58 test
<CharT
, std::tuple
<int>>();
59 test
<CharT
, std::tuple
<int, CharT
>>();
60 test
<CharT
, std::pair
<int, CharT
>>();
61 test
<CharT
, std::tuple
<int, CharT
, bool>>();
64 constexpr bool test() {
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
73 int main(int, char**) {
75 static_assert(test());