xref: /llvm-project/libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp (revision 6a54dfbfe534276d644d7f9c027f0deeb748dd53)
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 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
12 
13 // <format>
14 
15 // class range_formatter
16 // template<class charT, formattable<charT>... Ts>
17 //   struct formatter<pair-or-tuple<Ts...>, charT>
18 
19 // constexpr void set_separator(basic_string_view<charT> sep) noexcept;
20 
21 // Note this tests the basics of this function. It's tested in more detail in
22 // the format functions tests.
23 
24 #include <format>
25 #include <tuple>
26 #include <utility>
27 
28 #include "make_string.h"
29 
30 #define SV(S) MAKE_STRING_VIEW(CharT, S)
31 
32 template <class CharT, class Arg>
33 constexpr void test() {
34   std::formatter<Arg, CharT> formatter;
35   formatter.set_separator(SV("sep"));
36   // Note the SV macro may throw, so can't use it.
37   static_assert(noexcept(formatter.set_separator(std::basic_string_view<CharT>{})));
38 
39   // Note there is no direct way to validate this function modified the object.
40 }
41 
42 template <class CharT>
43 constexpr void test() {
44   test<CharT, std::tuple<int>>();
45   test<CharT, std::tuple<int, CharT>>();
46   test<CharT, std::pair<int, CharT>>();
47   test<CharT, std::tuple<int, CharT, bool>>();
48 }
49 
50 constexpr bool test() {
51   test<char>();
52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
53   test<wchar_t>();
54 #endif
55 
56   return true;
57 }
58 
59 int main(int, char**) {
60   test();
61   static_assert(test());
62 
63   return 0;
64 }
65