1fe6060f1SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 3fe6060f1SDimitry Andric// 4fe6060f1SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5fe6060f1SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6fe6060f1SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7fe6060f1SDimitry Andric// 8fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 9fe6060f1SDimitry Andric 10fe6060f1SDimitry Andric#ifndef _LIBCPP_FORMAT 11fe6060f1SDimitry Andric#define _LIBCPP_FORMAT 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric/* 14fe6060f1SDimitry Andric 15fe6060f1SDimitry Andricnamespace std { 16349cc55cSDimitry Andric // [format.context], class template basic_format_context 1704eeddc0SDimitry Andric template<class Out, class charT> class basic_format_context; 18349cc55cSDimitry Andric using format_context = basic_format_context<unspecified, char>; 19349cc55cSDimitry Andric using wformat_context = basic_format_context<unspecified, wchar_t>; 20349cc55cSDimitry Andric 21349cc55cSDimitry Andric // [format.args], class template basic_format_args 2204eeddc0SDimitry Andric template<class Context> class basic_format_args; 23349cc55cSDimitry Andric using format_args = basic_format_args<format_context>; 24349cc55cSDimitry Andric using wformat_args = basic_format_args<wformat_context>; 25349cc55cSDimitry Andric 2661cfbce3SDimitry Andric // [format.fmt.string], class template basic_format_string 2781ad6265SDimitry Andric template<class charT, class... Args> 2861cfbce3SDimitry Andric struct basic_format_string { // since C++23, exposition only before C++23 2961cfbce3SDimitry Andric private: 3061cfbce3SDimitry Andric basic_string_view<charT> str; // exposition only 3181ad6265SDimitry Andric 3261cfbce3SDimitry Andric public: 3361cfbce3SDimitry Andric template<class T> consteval basic_format_string(const T& s); 3461cfbce3SDimitry Andric 3561cfbce3SDimitry Andric constexpr basic_string_view<charT> get() const noexcept { return str; } 3661cfbce3SDimitry Andric }; 3781ad6265SDimitry Andric template<class... Args> 3861cfbce3SDimitry Andric using format_string = // since C++23, exposition only before C++23 3961cfbce3SDimitry Andric basic_format_string<char, type_identity_t<Args>...>; 4081ad6265SDimitry Andric template<class... Args> 4161cfbce3SDimitry Andric using wformat_string = // since C++23, exposition only before C++23 4261cfbce3SDimitry Andric basic_format_string<wchar_t, type_identity_t<Args>...>; 4381ad6265SDimitry Andric 44349cc55cSDimitry Andric // [format.functions], formatting functions 45349cc55cSDimitry Andric template<class... Args> 46753f127fSDimitry Andric string format(format-string<Args...> fmt, Args&&... args); 47349cc55cSDimitry Andric template<class... Args> 48753f127fSDimitry Andric wstring format(wformat-string<Args...> fmt, Args&&... args); 49349cc55cSDimitry Andric template<class... Args> 50753f127fSDimitry Andric string format(const locale& loc, format-string<Args...> fmt, Args&&... args); 51349cc55cSDimitry Andric template<class... Args> 52753f127fSDimitry Andric wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args); 53349cc55cSDimitry Andric 54349cc55cSDimitry Andric string vformat(string_view fmt, format_args args); 55349cc55cSDimitry Andric wstring vformat(wstring_view fmt, wformat_args args); 56349cc55cSDimitry Andric string vformat(const locale& loc, string_view fmt, format_args args); 57349cc55cSDimitry Andric wstring vformat(const locale& loc, wstring_view fmt, wformat_args args); 58349cc55cSDimitry Andric 59349cc55cSDimitry Andric template<class Out, class... Args> 60753f127fSDimitry Andric Out format_to(Out out, format-string<Args...> fmt, Args&&... args); 61349cc55cSDimitry Andric template<class Out, class... Args> 62753f127fSDimitry Andric Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args); 63349cc55cSDimitry Andric template<class Out, class... Args> 64753f127fSDimitry Andric Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args); 65349cc55cSDimitry Andric template<class Out, class... Args> 66753f127fSDimitry Andric Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args); 67349cc55cSDimitry Andric 68349cc55cSDimitry Andric template<class Out> 694824e7fdSDimitry Andric Out vformat_to(Out out, string_view fmt, format_args args); 70349cc55cSDimitry Andric template<class Out> 714824e7fdSDimitry Andric Out vformat_to(Out out, wstring_view fmt, wformat_args args); 72349cc55cSDimitry Andric template<class Out> 73349cc55cSDimitry Andric Out vformat_to(Out out, const locale& loc, string_view fmt, 744824e7fdSDimitry Andric format_args char> args); 75349cc55cSDimitry Andric template<class Out> 76349cc55cSDimitry Andric Out vformat_to(Out out, const locale& loc, wstring_view fmt, 774824e7fdSDimitry Andric wformat_args args); 78349cc55cSDimitry Andric 79349cc55cSDimitry Andric template<class Out> struct format_to_n_result { 80349cc55cSDimitry Andric Out out; 81349cc55cSDimitry Andric iter_difference_t<Out> size; 82349cc55cSDimitry Andric }; 83349cc55cSDimitry Andric template<class Out, class... Args> 84349cc55cSDimitry Andric format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, 85753f127fSDimitry Andric format-string<Args...> fmt, Args&&... args); 86349cc55cSDimitry Andric template<class Out, class... Args> 87349cc55cSDimitry Andric format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, 88753f127fSDimitry Andric wformat-string<Args...> fmt, Args&&... args); 89349cc55cSDimitry Andric template<class Out, class... Args> 90349cc55cSDimitry Andric format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, 9181ad6265SDimitry Andric const locale& loc, format-string<Args...> fmt, 92753f127fSDimitry Andric Args&&... args); 93349cc55cSDimitry Andric template<class Out, class... Args> 94349cc55cSDimitry Andric format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, 9581ad6265SDimitry Andric const locale& loc, wformat-string<Args...> fmt, 96753f127fSDimitry Andric Args&&... args); 97349cc55cSDimitry Andric 98349cc55cSDimitry Andric template<class... Args> 99753f127fSDimitry Andric size_t formatted_size(format-string<Args...> fmt, Args&&... args); 100349cc55cSDimitry Andric template<class... Args> 101753f127fSDimitry Andric size_t formatted_size(wformat-string<Args...> fmt, Args&&... args); 102349cc55cSDimitry Andric template<class... Args> 103753f127fSDimitry Andric size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args); 104349cc55cSDimitry Andric template<class... Args> 105753f127fSDimitry Andric size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, Args&&... args); 106349cc55cSDimitry Andric 107349cc55cSDimitry Andric // [format.formatter], formatter 10804eeddc0SDimitry Andric template<class T, class charT = char> struct formatter; 109349cc55cSDimitry Andric 110349cc55cSDimitry Andric // [format.parse.ctx], class template basic_format_parse_context 11104eeddc0SDimitry Andric template<class charT> class basic_format_parse_context; 112349cc55cSDimitry Andric using format_parse_context = basic_format_parse_context<char>; 113349cc55cSDimitry Andric using wformat_parse_context = basic_format_parse_context<wchar_t>; 114349cc55cSDimitry Andric 115*bdd1243dSDimitry Andric // [format.range], formatting of ranges 116*bdd1243dSDimitry Andric // [format.range.fmtkind], variable template format_kind 117*bdd1243dSDimitry Andric enum class range_format { // since C++23 118*bdd1243dSDimitry Andric disabled, 119*bdd1243dSDimitry Andric map, 120*bdd1243dSDimitry Andric set, 121*bdd1243dSDimitry Andric sequence, 122*bdd1243dSDimitry Andric string, 123*bdd1243dSDimitry Andric debug_string 124*bdd1243dSDimitry Andric }; 125*bdd1243dSDimitry Andric 126*bdd1243dSDimitry Andric template<class R> 127*bdd1243dSDimitry Andric constexpr unspecified format_kind = unspecified; // since C++23 128*bdd1243dSDimitry Andric 129*bdd1243dSDimitry Andric template<ranges::input_range R> 130*bdd1243dSDimitry Andric requires same_as<R, remove_cvref_t<R>> 131*bdd1243dSDimitry Andric constexpr range_format format_kind<R> = see below; // since C++23 132*bdd1243dSDimitry Andric 133*bdd1243dSDimitry Andric // [format.range.formatter], class template range_formatter 134*bdd1243dSDimitry Andric template<class T, class charT = char> 135*bdd1243dSDimitry Andric requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> 136*bdd1243dSDimitry Andric class range_formatter; // since C++23 137*bdd1243dSDimitry Andric 138*bdd1243dSDimitry Andric // [format.range.fmtdef], class template range-default-formatter 139*bdd1243dSDimitry Andric template<range_format K, ranges::input_range R, class charT> 140*bdd1243dSDimitry Andric struct range-default-formatter; // exposition only, since C++23 141*bdd1243dSDimitry Andric 142*bdd1243dSDimitry Andric // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr], 143*bdd1243dSDimitry Andric // specializations for maps, sets, and strings 144*bdd1243dSDimitry Andric template<ranges::input_range R, class charT> 145*bdd1243dSDimitry Andric requires (format_kind<R> != range_format::disabled) && 146*bdd1243dSDimitry Andric formattable<ranges::range_reference_t<R>, charT> 147*bdd1243dSDimitry Andric struct formatter<R, charT> : range-default-formatter<format_kind<R>, R, charT> { }; // since C++23 148*bdd1243dSDimitry Andric 149349cc55cSDimitry Andric // [format.arguments], arguments 150349cc55cSDimitry Andric // [format.arg], class template basic_format_arg 15104eeddc0SDimitry Andric template<class Context> class basic_format_arg; 152349cc55cSDimitry Andric 153349cc55cSDimitry Andric template<class Visitor, class Context> 154349cc55cSDimitry Andric see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); 155349cc55cSDimitry Andric 156349cc55cSDimitry Andric // [format.arg.store], class template format-arg-store 15704eeddc0SDimitry Andric template<class Context, class... Args> struct format-arg-store; // exposition only 158349cc55cSDimitry Andric 159349cc55cSDimitry Andric template<class Context = format_context, class... Args> 160349cc55cSDimitry Andric format-arg-store<Context, Args...> 161753f127fSDimitry Andric make_format_args(Args&&... args); 162349cc55cSDimitry Andric template<class... Args> 163349cc55cSDimitry Andric format-arg-store<wformat_context, Args...> 164753f127fSDimitry Andric make_wformat_args(Args&&... args); 165349cc55cSDimitry Andric 166fe6060f1SDimitry Andric // [format.error], class format_error 16704eeddc0SDimitry Andric class format_error; 168fe6060f1SDimitry Andric} 169fe6060f1SDimitry Andric 170fe6060f1SDimitry Andric*/ 171fe6060f1SDimitry Andric 17281ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 173349cc55cSDimitry Andric// Make sure all feature-test macros are available. 1746e75b2fbSDimitry Andric#include <version> 175fcaf7f86SDimitry Andric// Enable the contents of the header only when libc++ was built with experimental features enabled. 1766e75b2fbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) 1776e75b2fbSDimitry Andric 178fe6060f1SDimitry Andric#include <__config> 17981ad6265SDimitry Andric#include <__format/buffer.h> 18081ad6265SDimitry Andric#include <__format/concepts.h> 181*bdd1243dSDimitry Andric#include <__format/container_adaptor.h> 18281ad6265SDimitry Andric#include <__format/enable_insertable.h> 183349cc55cSDimitry Andric#include <__format/format_arg.h> 18481ad6265SDimitry Andric#include <__format/format_arg_store.h> 185349cc55cSDimitry Andric#include <__format/format_args.h> 186349cc55cSDimitry Andric#include <__format/format_context.h> 187fe6060f1SDimitry Andric#include <__format/format_error.h> 188*bdd1243dSDimitry Andric#include <__format/format_functions.h> 189349cc55cSDimitry Andric#include <__format/format_fwd.h> 190fe6060f1SDimitry Andric#include <__format/format_parse_context.h> 191349cc55cSDimitry Andric#include <__format/format_string.h> 192349cc55cSDimitry Andric#include <__format/format_to_n_result.h> 193349cc55cSDimitry Andric#include <__format/formatter.h> 194349cc55cSDimitry Andric#include <__format/formatter_bool.h> 195349cc55cSDimitry Andric#include <__format/formatter_char.h> 19604eeddc0SDimitry Andric#include <__format/formatter_floating_point.h> 197349cc55cSDimitry Andric#include <__format/formatter_integer.h> 19804eeddc0SDimitry Andric#include <__format/formatter_pointer.h> 199349cc55cSDimitry Andric#include <__format/formatter_string.h> 200*bdd1243dSDimitry Andric#include <__format/formatter_tuple.h> 201349cc55cSDimitry Andric#include <__format/parser_std_format_spec.h> 202*bdd1243dSDimitry Andric#include <__format/range_default_formatter.h> 203*bdd1243dSDimitry Andric#include <__format/range_formatter.h> 204fcaf7f86SDimitry Andric#include <__format/unicode.h> 205fe6060f1SDimitry Andric 206fe6060f1SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 207fe6060f1SDimitry Andric# pragma GCC system_header 208fe6060f1SDimitry Andric#endif 209fe6060f1SDimitry Andric 2106e75b2fbSDimitry Andric#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) 2116e75b2fbSDimitry Andric 212fe6060f1SDimitry Andric#endif // _LIBCPP_FORMAT 213