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
9 
10 // <format>
11 
12 // Class typedefs:
13 // template<class Out, class charT>
14 // class basic_format_context {
15 // public:
16 //   using iterator = Out
17 //   using char_type = charT;
18 //   template<class T> using formatter_type = formatter<T, charT>;
19 // }
20 //
21 // Namespace std typedefs:
22 // using format_context = basic_format_context<unspecified, char>;
23 // using wformat_context = basic_format_context<unspecified, wchar_t>;
24 
25 #include <format>
26 #include <iterator>
27 #include <string_view>
28 #include <type_traits>
29 
30 #include "test_macros.h"
31 
32 template <class OutIt, class CharT>
test()33 constexpr void test() {
34   static_assert(
35       std::is_same_v<typename std::basic_format_context<OutIt, CharT>::iterator,
36                      OutIt>);
37   static_assert(
38       std::is_same_v<
39           typename std::basic_format_context<OutIt, CharT>::char_type, CharT>);
40   static_assert(std::is_same_v<typename std::basic_format_context<
41                                    OutIt, CharT>::template formatter_type<bool>,
42                                std::formatter<bool, CharT>>);
43   static_assert(
44       std::is_same_v<typename std::basic_format_context<
45                          OutIt, CharT>::template formatter_type<CharT>,
46                      std::formatter<CharT, CharT>>);
47   static_assert(std::is_same_v<typename std::basic_format_context<
48                                    OutIt, CharT>::template formatter_type<int>,
49                                std::formatter<int, CharT>>);
50   static_assert(
51       std::is_same_v<typename std::basic_format_context<
52                          OutIt, CharT>::template formatter_type<unsigned>,
53                      std::formatter<unsigned, CharT>>);
54   static_assert(
55       std::is_same_v<typename std::basic_format_context<
56                          OutIt, CharT>::template formatter_type<long long>,
57                      std::formatter<long long, CharT>>);
58   static_assert(
59       std::is_same_v<typename std::basic_format_context<OutIt, CharT>::
60                          template formatter_type<unsigned long long>,
61                      std::formatter<unsigned long long, CharT>>);
62 #ifndef TEST_HAS_NO_INT128
63   static_assert(
64       std::is_same_v<typename std::basic_format_context<
65                          OutIt, CharT>::template formatter_type<__int128_t>,
66                      std::formatter<__int128_t, CharT>>);
67   static_assert(
68       std::is_same_v<typename std::basic_format_context<
69                          OutIt, CharT>::template formatter_type<__uint128_t>,
70                      std::formatter<__uint128_t, CharT>>);
71 #endif
72   static_assert(
73       std::is_same_v<typename std::basic_format_context<
74                          OutIt, CharT>::template formatter_type<float>,
75                      std::formatter<float, CharT>>);
76   static_assert(
77       std::is_same_v<typename std::basic_format_context<
78                          OutIt, CharT>::template formatter_type<double>,
79                      std::formatter<double, CharT>>);
80   static_assert(
81       std::is_same_v<typename std::basic_format_context<
82                          OutIt, CharT>::template formatter_type<long double>,
83                      std::formatter<long double, CharT>>);
84   static_assert(
85       std::is_same_v<typename std::basic_format_context<
86                          OutIt, CharT>::template formatter_type<const CharT*>,
87                      std::formatter<const CharT*, CharT>>);
88   static_assert(
89       std::is_same_v<typename std::basic_format_context<OutIt, CharT>::
90                          template formatter_type<std::basic_string_view<CharT>>,
91                      std::formatter<std::basic_string_view<CharT>, CharT>>);
92   static_assert(
93       std::is_same_v<typename std::basic_format_context<
94                          OutIt, CharT>::template formatter_type<const void*>,
95                      std::formatter<const void*, CharT>>);
96 }
97 
test()98 constexpr void test() {
99   test<std::back_insert_iterator<std::__format::__output_buffer<char>>, char>();
100 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
101   test<std::back_insert_iterator<std::__format::__output_buffer<wchar_t>>,
102        wchar_t>();
103 #endif
104 }
105 
106 template <class, class>
107 constexpr bool is_basic_format_context_specialization = false;
108 template <class It, class CharT>
109 constexpr bool is_basic_format_context_specialization<std::basic_format_context<It, CharT>, CharT> = true;
110 
111 static_assert(is_basic_format_context_specialization<std::format_context, char>);
112 static_assert(
113     std::is_same_v<
114         std::format_context,
115         std::basic_format_context<
116             std::back_insert_iterator<std::__format::__output_buffer<char>>,
117             char>>);
118 
119 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
120 static_assert(is_basic_format_context_specialization<std::wformat_context, wchar_t>);
121 LIBCPP_STATIC_ASSERT(
122     std::is_same_v<
123         std::wformat_context,
124         std::basic_format_context<
125             std::back_insert_iterator< std::__format::__output_buffer<wchar_t>>,
126             wchar_t>>);
127 #endif
128