| 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 | template<class T> |
| 130 | constexpr bool enable_nonlocking_formatter_optimization = false; // since C++23 |
| 131 | |
| 132 | // [format.parse.ctx], class template basic_format_parse_context |
| 133 | template<class charT> class basic_format_parse_context; |
| 134 | using format_parse_context = basic_format_parse_context<char>; |
| 135 | using wformat_parse_context = basic_format_parse_context<wchar_t>; |
| 136 | |
| 137 | // [format.range], formatting of ranges |
| 138 | // [format.range.fmtkind], variable template format_kind |
| 139 | enum class range_format { // since C++23 |
| 140 | disabled, |
| 141 | map, |
| 142 | set, |
| 143 | sequence, |
| 144 | string, |
| 145 | debug_string |
| 146 | }; |
| 147 | |
| 148 | template<class R> |
| 149 | constexpr unspecified format_kind = unspecified; // since C++23 |
| 150 | |
| 151 | template<ranges::input_range R> |
| 152 | requires same_as<R, remove_cvref_t<R>> |
| 153 | constexpr range_format format_kind<R> = see below; // since C++23 |
| 154 | |
| 155 | // [format.range.formatter], class template range_formatter |
| 156 | template<class T, class charT = char> |
| 157 | requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> |
| 158 | class range_formatter; // since C++23 |
| 159 | |
| 160 | // [format.range.fmtdef], class template range-default-formatter |
| 161 | template<range_format K, ranges::input_range R, class charT> |
| 162 | struct range-default-formatter; // exposition only, since C++23 |
| 163 | |
| 164 | // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr], |
| 165 | // specializations for maps, sets, and strings |
| 166 | template<ranges::input_range R, class charT> |
| 167 | requires (format_kind<R> != range_format::disabled) && |
| 168 | formattable<ranges::range_reference_t<R>, charT> |
| 169 | struct formatter<R, charT> : range-default-formatter<format_kind<R>, R, charT> { }; // since C++23 |
| 170 | |
| 171 | // [format.arguments], arguments |
| 172 | // [format.arg], class template basic_format_arg |
| 173 | template<class Context> class basic_format_arg; |
| 174 | |
| 175 | template<class Visitor, class Context> |
| 176 | see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26 |
| 177 | |
| 178 | // [format.arg.store], class template format-arg-store |
| 179 | template<class Context, class... Args> struct format-arg-store; // exposition only |
| 180 | |
| 181 | template<class Context = format_context, class... Args> |
| 182 | format-arg-store<Context, Args...> |
| 183 | make_format_args(Args&... args); |
| 184 | template<class... Args> |
| 185 | format-arg-store<wformat_context, Args...> |
| 186 | make_wformat_args(Args&... args); |
| 187 | |
| 188 | // [format.error], class format_error |
| 189 | class format_error; |
| 190 | } |
| 191 | |
| 192 | */ |
| 193 | |
| 194 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 195 | # include <__cxx03/__config> |
| 196 | #else |
| 197 | # include <__config> |
| 198 | |
| 199 | # if _LIBCPP_STD_VER >= 20 |
| 200 | # include <__format/buffer.h> |
| 201 | # include <__format/concepts.h> |
| 202 | # include <__format/container_adaptor.h> |
| 203 | # include <__format/enable_insertable.h> |
| 204 | # include <__format/escaped_output_table.h> |
| 205 | # include <__format/extended_grapheme_cluster_table.h> |
| 206 | # include <__format/format_arg.h> |
| 207 | # include <__format/format_arg_store.h> |
| 208 | # include <__format/format_args.h> |
| 209 | # include <__format/format_context.h> |
| 210 | # include <__format/format_error.h> |
| 211 | # include <__format/format_functions.h> |
| 212 | # include <__format/format_parse_context.h> |
| 213 | # include <__format/format_string.h> |
| 214 | # include <__format/format_to_n_result.h> |
| 215 | # include <__format/formatter.h> |
| 216 | # include <__format/formatter_bool.h> |
| 217 | # include <__format/formatter_char.h> |
| 218 | # include <__format/formatter_floating_point.h> |
| 219 | # include <__format/formatter_integer.h> |
| 220 | # include <__format/formatter_pointer.h> |
| 221 | # include <__format/formatter_string.h> |
| 222 | # include <__format/formatter_tuple.h> |
| 223 | # include <__format/parser_std_format_spec.h> |
| 224 | # include <__format/range_default_formatter.h> |
| 225 | # include <__format/range_formatter.h> |
| 226 | # include <__format/unicode.h> |
| 227 | # include <__fwd/format.h> |
| 228 | # endif |
| 229 | |
| 230 | # include <version> |
| 231 | |
| 232 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 233 | # pragma GCC system_header |
| 234 | # endif |
| 235 | |
| 236 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 237 | # include <array> |
| 238 | # include <cctype> |
| 239 | # include <cerrno> |
| 240 | # include <clocale> |
| 241 | # include <cmath> |
| 242 | # include <cstddef> |
| 243 | # include <cstdint> |
| 244 | # include <cstdlib> |
| 245 | # include <cstring> |
| 246 | # include <initializer_list> |
| 247 | # include <limits> |
| 248 | # include <locale> |
| 249 | # include <new> |
| 250 | # include <optional> |
| 251 | # include <queue> |
| 252 | # include <stack> |
| 253 | # include <stdexcept> |
| 254 | # include <string> |
| 255 | # include <string_view> |
| 256 | # include <tuple> |
| 257 | |
| 258 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 259 | # include <cwchar> |
| 260 | # endif |
| 261 | # endif |
| 262 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 263 | |
| 264 | #endif // _LIBCPP_FORMAT |
| 265 | |