1 | // -*- C++ -*- |
2 | //===----------------------------------------------------------------------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef _LIBCPP_FORMAT |
11 | #define _LIBCPP_FORMAT |
12 | |
13 | /* |
14 | |
15 | namespace std { |
16 | // [format.context], class template basic_format_context |
17 | template<class Out, class charT> class basic_format_context; |
18 | using format_context = basic_format_context<unspecified, char>; |
19 | using wformat_context = basic_format_context<unspecified, wchar_t>; |
20 | |
21 | // [format.args], class template basic_format_args |
22 | template<class Context> class basic_format_args; |
23 | using format_args = basic_format_args<format_context>; |
24 | using wformat_args = basic_format_args<wformat_context>; |
25 | |
26 | // [format.fmt.string], class template basic_format_string |
27 | template<class charT, class... Args> |
28 | struct basic_format_string { // since C++23, exposition only before C++23 |
29 | private: |
30 | basic_string_view<charT> str; // exposition only |
31 | |
32 | public: |
33 | template<class T> consteval basic_format_string(const T& s); |
34 | basic_format_string(runtime-format-string<charT> s) noexcept : str(s.str) {} // since C++26 |
35 | |
36 | constexpr basic_string_view<charT> get() const noexcept { return str; } |
37 | }; |
38 | template<class... Args> |
39 | using format_string = // since C++23, exposition only before C++23 |
40 | basic_format_string<char, type_identity_t<Args>...>; |
41 | template<class... Args> |
42 | using wformat_string = // since C++23, exposition only before C++23 |
43 | basic_format_string<wchar_t, type_identity_t<Args>...>; |
44 | |
45 | template<class charT> struct runtime-format-string { // since C++26, exposition-only |
46 | private: |
47 | basic_string_view<charT> str; // exposition-only |
48 | |
49 | public: |
50 | runtime-format-string(basic_string_view<charT> s) noexcept : str(s) {} |
51 | |
52 | runtime-format-string(const runtime-format-string&) = delete; |
53 | runtime-format-string& operator=(const runtime-format-string&) = delete; |
54 | }; |
55 | |
56 | runtime-format-string<char> runtime_format(string_view fmt) noexcept { |
57 | return fmt; |
58 | } |
59 | runtime-format-string<wchar_t> runtime_format(wstring_view fmt) noexcept { |
60 | return fmt; |
61 | } |
62 | |
63 | // [format.functions], formatting functions |
64 | template<class... Args> |
65 | string format(format-string<Args...> fmt, Args&&... args); |
66 | template<class... Args> |
67 | wstring format(wformat-string<Args...> fmt, Args&&... args); |
68 | template<class... Args> |
69 | string format(const locale& loc, format-string<Args...> fmt, Args&&... args); |
70 | template<class... Args> |
71 | wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args); |
72 | |
73 | string vformat(string_view fmt, format_args args); |
74 | wstring vformat(wstring_view fmt, wformat_args args); |
75 | string vformat(const locale& loc, string_view fmt, format_args args); |
76 | wstring vformat(const locale& loc, wstring_view fmt, wformat_args args); |
77 | |
78 | template<class Out, class... Args> |
79 | Out format_to(Out out, format-string<Args...> fmt, Args&&... args); |
80 | template<class Out, class... Args> |
81 | Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args); |
82 | template<class Out, class... Args> |
83 | Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args); |
84 | template<class Out, class... Args> |
85 | Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args); |
86 | |
87 | template<class Out> |
88 | Out vformat_to(Out out, string_view fmt, format_args args); |
89 | template<class Out> |
90 | Out vformat_to(Out out, wstring_view fmt, wformat_args args); |
91 | template<class Out> |
92 | Out vformat_to(Out out, const locale& loc, string_view fmt, |
93 | format_args char> args); |
94 | template<class Out> |
95 | Out vformat_to(Out out, const locale& loc, wstring_view fmt, |
96 | wformat_args args); |
97 | |
98 | template<class Out> struct format_to_n_result { |
99 | Out out; |
100 | iter_difference_t<Out> size; |
101 | }; |
102 | template<class Out, class... Args> |
103 | format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, |
104 | format-string<Args...> fmt, Args&&... args); |
105 | template<class Out, class... Args> |
106 | format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, |
107 | wformat-string<Args...> fmt, Args&&... args); |
108 | template<class Out, class... Args> |
109 | format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, |
110 | const locale& loc, format-string<Args...> fmt, |
111 | Args&&... args); |
112 | template<class Out, class... Args> |
113 | format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, |
114 | const locale& loc, wformat-string<Args...> fmt, |
115 | Args&&... args); |
116 | |
117 | template<class... Args> |
118 | size_t formatted_size(format-string<Args...> fmt, Args&&... args); |
119 | template<class... Args> |
120 | size_t formatted_size(wformat-string<Args...> fmt, Args&&... args); |
121 | template<class... Args> |
122 | size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args); |
123 | template<class... Args> |
124 | size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, Args&&... args); |
125 | |
126 | // [format.formatter], formatter |
127 | template<class T, class charT = char> struct formatter; |
128 | |
129 | // [format.parse.ctx], class template basic_format_parse_context |
130 | template<class charT> class basic_format_parse_context; |
131 | using format_parse_context = basic_format_parse_context<char>; |
132 | using wformat_parse_context = basic_format_parse_context<wchar_t>; |
133 | |
134 | // [format.range], formatting of ranges |
135 | // [format.range.fmtkind], variable template format_kind |
136 | enum class range_format { // since C++23 |
137 | disabled, |
138 | map, |
139 | set, |
140 | sequence, |
141 | string, |
142 | debug_string |
143 | }; |
144 | |
145 | template<class R> |
146 | constexpr unspecified format_kind = unspecified; // since C++23 |
147 | |
148 | template<ranges::input_range R> |
149 | requires same_as<R, remove_cvref_t<R>> |
150 | constexpr range_format format_kind<R> = see below; // since C++23 |
151 | |
152 | // [format.range.formatter], class template range_formatter |
153 | template<class T, class charT = char> |
154 | requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> |
155 | class range_formatter; // since C++23 |
156 | |
157 | // [format.range.fmtdef], class template range-default-formatter |
158 | template<range_format K, ranges::input_range R, class charT> |
159 | struct range-default-formatter; // exposition only, since C++23 |
160 | |
161 | // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr], |
162 | // specializations for maps, sets, and strings |
163 | template<ranges::input_range R, class charT> |
164 | requires (format_kind<R> != range_format::disabled) && |
165 | formattable<ranges::range_reference_t<R>, charT> |
166 | struct formatter<R, charT> : range-default-formatter<format_kind<R>, R, charT> { }; // since C++23 |
167 | |
168 | // [format.arguments], arguments |
169 | // [format.arg], class template basic_format_arg |
170 | template<class Context> class basic_format_arg; |
171 | |
172 | template<class Visitor, class Context> |
173 | see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26 |
174 | |
175 | // [format.arg.store], class template format-arg-store |
176 | template<class Context, class... Args> struct format-arg-store; // exposition only |
177 | |
178 | template<class Context = format_context, class... Args> |
179 | format-arg-store<Context, Args...> |
180 | make_format_args(Args&... args); |
181 | template<class... Args> |
182 | format-arg-store<wformat_context, Args...> |
183 | make_wformat_args(Args&... args); |
184 | |
185 | // [format.error], class format_error |
186 | class format_error; |
187 | } |
188 | |
189 | */ |
190 | |
191 | #include <__config> |
192 | |
193 | #if _LIBCPP_STD_VER >= 20 |
194 | # include <__format/buffer.h> |
195 | # include <__format/concepts.h> |
196 | # include <__format/container_adaptor.h> |
197 | # include <__format/enable_insertable.h> |
198 | # include <__format/escaped_output_table.h> |
199 | # include <__format/extended_grapheme_cluster_table.h> |
200 | # include <__format/format_arg.h> |
201 | # include <__format/format_arg_store.h> |
202 | # include <__format/format_args.h> |
203 | # include <__format/format_context.h> |
204 | # include <__format/format_error.h> |
205 | # include <__format/format_functions.h> |
206 | # include <__format/format_parse_context.h> |
207 | # include <__format/format_string.h> |
208 | # include <__format/format_to_n_result.h> |
209 | # include <__format/formatter.h> |
210 | # include <__format/formatter_bool.h> |
211 | # include <__format/formatter_char.h> |
212 | # include <__format/formatter_floating_point.h> |
213 | # include <__format/formatter_integer.h> |
214 | # include <__format/formatter_pointer.h> |
215 | # include <__format/formatter_string.h> |
216 | # include <__format/formatter_tuple.h> |
217 | # include <__format/parser_std_format_spec.h> |
218 | # include <__format/range_default_formatter.h> |
219 | # include <__format/range_formatter.h> |
220 | # include <__format/unicode.h> |
221 | # include <__fwd/format.h> |
222 | #endif |
223 | |
224 | #include <version> |
225 | |
226 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
227 | # pragma GCC system_header |
228 | #endif |
229 | |
230 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
231 | # include <array> |
232 | # include <cctype> |
233 | # include <cerrno> |
234 | # include <clocale> |
235 | # include <cmath> |
236 | # include <cstddef> |
237 | # include <cstdint> |
238 | # include <cstdlib> |
239 | # include <cstring> |
240 | # include <initializer_list> |
241 | # include <limits> |
242 | # include <locale> |
243 | # include <new> |
244 | # include <optional> |
245 | # include <queue> |
246 | # include <stack> |
247 | # include <stdexcept> |
248 | # include <string> |
249 | # include <string_view> |
250 | # include <tuple> |
251 | |
252 | # if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) |
253 | # include <cwchar> |
254 | # endif |
255 | #endif |
256 | |
257 | #endif // _LIBCPP_FORMAT |
258 | |