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 15namespace 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); 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 <__assert> // all public C++ headers provide the assertion handler 192#include <__config> 193#include <__format/buffer.h> 194#include <__format/concepts.h> 195#include <__format/container_adaptor.h> 196#include <__format/enable_insertable.h> 197#include <__format/format_arg.h> 198#include <__format/format_arg_store.h> 199#include <__format/format_args.h> 200#include <__format/format_context.h> 201#include <__format/format_error.h> 202#include <__format/format_functions.h> 203#include <__format/format_fwd.h> 204#include <__format/format_parse_context.h> 205#include <__format/format_string.h> 206#include <__format/format_to_n_result.h> 207#include <__format/formatter.h> 208#include <__format/formatter_bool.h> 209#include <__format/formatter_char.h> 210#include <__format/formatter_floating_point.h> 211#include <__format/formatter_integer.h> 212#include <__format/formatter_pointer.h> 213#include <__format/formatter_string.h> 214#include <__format/formatter_tuple.h> 215#include <__format/parser_std_format_spec.h> 216#include <__format/range_default_formatter.h> 217#include <__format/range_formatter.h> 218#include <__format/unicode.h> 219#include <version> 220 221#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 222# pragma GCC system_header 223#endif 224 225#endif // _LIBCPP_FORMAT 226