xref: /freebsd/contrib/llvm-project/libcxx/include/format (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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
35      constexpr basic_string_view<charT> get() const noexcept { return str; }
36    };
37  template<class... Args>
38    using format_string =                                       // since C++23, exposition only before C++23
39      basic_format_string<char, type_identity_t<Args>...>;
40  template<class... Args>
41    using wformat_string =                                      // since C++23, exposition only before C++23
42      basic_format_string<wchar_t, type_identity_t<Args>...>;
43
44  // [format.functions], formatting functions
45  template<class... Args>
46    string format(format-string<Args...> fmt, Args&&... args);
47  template<class... Args>
48    wstring format(wformat-string<Args...> fmt, Args&&... args);
49  template<class... Args>
50    string format(const locale& loc, format-string<Args...> fmt, Args&&... args);
51  template<class... Args>
52    wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args);
53
54  string vformat(string_view fmt, format_args args);
55  wstring vformat(wstring_view fmt, wformat_args args);
56  string vformat(const locale& loc, string_view fmt, format_args args);
57  wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
58
59  template<class Out, class... Args>
60    Out format_to(Out out, format-string<Args...> fmt, Args&&... args);
61  template<class Out, class... Args>
62    Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args);
63  template<class Out, class... Args>
64    Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args);
65  template<class Out, class... Args>
66    Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args);
67
68  template<class Out>
69    Out vformat_to(Out out, string_view fmt, format_args args);
70  template<class Out>
71    Out vformat_to(Out out, wstring_view fmt, wformat_args args);
72  template<class Out>
73    Out vformat_to(Out out, const locale& loc, string_view fmt,
74                   format_args char> args);
75  template<class Out>
76    Out vformat_to(Out out, const locale& loc, wstring_view fmt,
77                   wformat_args args);
78
79  template<class Out> struct format_to_n_result {
80    Out out;
81    iter_difference_t<Out> size;
82  };
83  template<class Out, class... Args>
84    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
85                                        format-string<Args...> fmt, Args&&... args);
86  template<class Out, class... Args>
87    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
88                                        wformat-string<Args...> fmt, Args&&... args);
89  template<class Out, class... Args>
90    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
91                                        const locale& loc, format-string<Args...> fmt,
92                                        Args&&... args);
93  template<class Out, class... Args>
94    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
95                                        const locale& loc, wformat-string<Args...> fmt,
96                                        Args&&... args);
97
98  template<class... Args>
99    size_t formatted_size(format-string<Args...> fmt, Args&&... args);
100  template<class... Args>
101    size_t formatted_size(wformat-string<Args...> fmt, Args&&... args);
102  template<class... Args>
103    size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args);
104  template<class... Args>
105    size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, Args&&... args);
106
107  // [format.formatter], formatter
108  template<class T, class charT = char> struct formatter;
109
110  // [format.parse.ctx], class template basic_format_parse_context
111  template<class charT> class basic_format_parse_context;
112  using format_parse_context = basic_format_parse_context<char>;
113  using wformat_parse_context = basic_format_parse_context<wchar_t>;
114
115  // [format.range], formatting of ranges
116  // [format.range.fmtkind], variable template format_kind
117  enum class range_format {                                     // since C++23
118    disabled,
119    map,
120    set,
121    sequence,
122    string,
123    debug_string
124  };
125
126  template<class R>
127    constexpr unspecified format_kind = unspecified;            // since C++23
128
129  template<ranges::input_range R>
130      requires same_as<R, remove_cvref_t<R>>
131    constexpr range_format format_kind<R> = see below;          // since C++23
132
133  // [format.range.formatter], class template range_formatter
134  template<class T, class charT = char>
135    requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
136  class range_formatter;                                        // since C++23
137
138  // [format.range.fmtdef], class template range-default-formatter
139  template<range_format K, ranges::input_range R, class charT>
140    struct range-default-formatter;                             // exposition only, since C++23
141
142  // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr],
143  // specializations for maps, sets, and strings
144  template<ranges::input_range R, class charT>
145    requires (format_kind<R> != range_format::disabled) &&
146             formattable<ranges::range_reference_t<R>, charT>
147  struct formatter<R, charT> : range-default-formatter<format_kind<R>, R, charT> { }; // since C++23
148
149  // [format.arguments], arguments
150  // [format.arg], class template basic_format_arg
151  template<class Context> class basic_format_arg;
152
153  template<class Visitor, class Context>
154    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
155
156  // [format.arg.store], class template format-arg-store
157  template<class Context, class... Args> struct format-arg-store;      // exposition only
158
159  template<class Context = format_context, class... Args>
160    format-arg-store<Context, Args...>
161      make_format_args(Args&&... args);
162  template<class... Args>
163    format-arg-store<wformat_context, Args...>
164      make_wformat_args(Args&&... args);
165
166  // [format.error], class format_error
167  class format_error;
168}
169
170*/
171
172#include <__assert> // all public C++ headers provide the assertion handler
173#include <__config>
174#include <__format/buffer.h>
175#include <__format/concepts.h>
176#include <__format/container_adaptor.h>
177#include <__format/enable_insertable.h>
178#include <__format/format_arg.h>
179#include <__format/format_arg_store.h>
180#include <__format/format_args.h>
181#include <__format/format_context.h>
182#include <__format/format_error.h>
183#include <__format/format_functions.h>
184#include <__format/format_fwd.h>
185#include <__format/format_parse_context.h>
186#include <__format/format_string.h>
187#include <__format/format_to_n_result.h>
188#include <__format/formatter.h>
189#include <__format/formatter_bool.h>
190#include <__format/formatter_char.h>
191#include <__format/formatter_floating_point.h>
192#include <__format/formatter_integer.h>
193#include <__format/formatter_pointer.h>
194#include <__format/formatter_string.h>
195#include <__format/formatter_tuple.h>
196#include <__format/parser_std_format_spec.h>
197#include <__format/range_default_formatter.h>
198#include <__format/range_formatter.h>
199#include <__format/unicode.h>
200#include <version>
201
202#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
203#  pragma GCC system_header
204#endif
205
206#endif // _LIBCPP_FORMAT
207