annotate dep/fmt/include/fmt/compile.h @ 360:6ca952f6a95c

CI/linux: need desktop-file-utils package
author Paper <paper@paper.us.eu.org>
date Mon, 15 Jul 2024 01:09:52 -0400
parents 4aeffed717ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
329
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 // Formatting library for C++ - experimental format string compilation
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 //
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 // Copyright (c) 2012 - present, Victor Zverovich and fmt contributors
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 // All rights reserved.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5 //
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6 // For the license information refer to format.h.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8 #ifndef FMT_COMPILE_H_
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 #define FMT_COMPILE_H_
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 #include "format.h"
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 FMT_BEGIN_NAMESPACE
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 namespace detail {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 template <typename Char, typename InputIt>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17 FMT_CONSTEXPR inline auto copy_str(InputIt begin, InputIt end,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 counting_iterator it) -> counting_iterator {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 return it + (end - begin);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 // A compile-time string which is compiled into fast formatting code.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 class compiled_string {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 template <typename S>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26 struct is_compiled_string : std::is_base_of<compiled_string, S> {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 /**
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 \rst
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 Converts a string literal *s* into a format string that will be parsed at
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 compile time and converted into efficient formatting code. Requires C++17
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 ``constexpr if`` compiler support.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34 **Example**::
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 // Converts 42 into std::string using the most efficient method and no
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37 // runtime format string processing.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 std::string s = fmt::format(FMT_COMPILE("{}"), 42);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 \endrst
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 */
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41 #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 # define FMT_COMPILE(s) \
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43 FMT_STRING_IMPL(s, fmt::detail::compiled_string, explicit)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 #else
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45 # define FMT_COMPILE(s) FMT_STRING(s)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46 #endif
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 #if FMT_USE_NONTYPE_TEMPLATE_ARGS
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49 template <typename Char, size_t N,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 fmt::detail_exported::fixed_string<Char, N> Str>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 struct udl_compiled_string : compiled_string {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53 explicit constexpr operator basic_string_view<char_type>() const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 return {Str.data, N - 1};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57 #endif
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 template <typename T, typename... Tail>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 auto first(const T& value, const Tail&...) -> const T& {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61 return value;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65 template <typename... Args> struct type_list {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 // Returns a reference to the argument at index N from [first, rest...].
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 template <int N, typename T, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 constexpr const auto& get([[maybe_unused]] const T& first,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 [[maybe_unused]] const Args&... rest) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 static_assert(N < 1 + sizeof...(Args), "index is out of bounds");
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72 if constexpr (N == 0)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73 return first;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 else
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75 return detail::get<N - 1>(rest...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
77
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
78 template <typename Char, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79 constexpr int get_arg_index_by_name(basic_string_view<Char> name,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80 type_list<Args...>) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81 return get_arg_index_by_name<Args...>(name);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
82 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
84 template <int N, typename> struct get_type_impl;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
86 template <int N, typename... Args> struct get_type_impl<N, type_list<Args...>> {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
87 using type =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
88 remove_cvref_t<decltype(detail::get<N>(std::declval<Args>()...))>;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
89 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
90
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
91 template <int N, typename T>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 using get_type = typename get_type_impl<N, T>::type;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94 template <typename T> struct is_compiled_format : std::false_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96 template <typename Char> struct text {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97 basic_string_view<Char> data;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 constexpr OutputIt format(OutputIt out, const Args&...) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 return write<Char>(out, data);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
103 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
104 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
105
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
106 template <typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
107 struct is_compiled_format<text<Char>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
108
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
109 template <typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
110 constexpr text<Char> make_text(basic_string_view<Char> s, size_t pos,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
111 size_t size) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
112 return {{&s[pos], size}};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
113 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
114
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
115 template <typename Char> struct code_unit {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
116 Char value;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
117 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
118
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
119 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
120 constexpr OutputIt format(OutputIt out, const Args&...) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
121 *out++ = value;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
122 return out;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
123 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
124 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
125
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
126 // This ensures that the argument type is convertible to `const T&`.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
127 template <typename T, int N, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
128 constexpr const T& get_arg_checked(const Args&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
129 const auto& arg = detail::get<N>(args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
130 if constexpr (detail::is_named_arg<remove_cvref_t<decltype(arg)>>()) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
131 return arg.value;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
132 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
133 return arg;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
134 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
135 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
136
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
137 template <typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
138 struct is_compiled_format<code_unit<Char>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
139
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
140 // A replacement field that refers to argument N.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
141 template <typename Char, typename T, int N> struct field {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
142 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
143
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
144 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
145 constexpr OutputIt format(OutputIt out, const Args&... args) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
146 const T& arg = get_arg_checked<T, N>(args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
147 if constexpr (std::is_convertible_v<T, basic_string_view<Char>>) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
148 auto s = basic_string_view<Char>(arg);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
149 return copy_str<Char>(s.begin(), s.end(), out);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
150 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
151 return write<Char>(out, arg);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
152 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
153 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
154
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
155 template <typename Char, typename T, int N>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
156 struct is_compiled_format<field<Char, T, N>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
157
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
158 // A replacement field that refers to argument with name.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
159 template <typename Char> struct runtime_named_field {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
160 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
161 basic_string_view<Char> name;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
162
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
163 template <typename OutputIt, typename T>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
164 constexpr static bool try_format_argument(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
165 OutputIt& out,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
166 // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
167 [[maybe_unused]] basic_string_view<Char> arg_name, const T& arg) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
168 if constexpr (is_named_arg<typename std::remove_cv<T>::type>::value) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
169 if (arg_name == arg.name) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
170 out = write<Char>(out, arg.value);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
171 return true;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
172 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
173 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
174 return false;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
175 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
176
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
177 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
178 constexpr OutputIt format(OutputIt out, const Args&... args) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
179 bool found = (try_format_argument(out, name, args) || ...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
180 if (!found) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
181 FMT_THROW(format_error("argument with specified name is not found"));
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
182 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
183 return out;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
184 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
185 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
186
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
187 template <typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
188 struct is_compiled_format<runtime_named_field<Char>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
189
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
190 // A replacement field that refers to argument N and has format specifiers.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
191 template <typename Char, typename T, int N> struct spec_field {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
192 using char_type = Char;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
193 formatter<T, Char> fmt;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
194
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
195 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
196 constexpr FMT_INLINE OutputIt format(OutputIt out,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
197 const Args&... args) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
198 const auto& vargs =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
199 fmt::make_format_args<basic_format_context<OutputIt, Char>>(args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
200 basic_format_context<OutputIt, Char> ctx(out, vargs);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
201 return fmt.format(get_arg_checked<T, N>(args...), ctx);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
202 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
203 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
204
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
205 template <typename Char, typename T, int N>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
206 struct is_compiled_format<spec_field<Char, T, N>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
207
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
208 template <typename L, typename R> struct concat {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
209 L lhs;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
210 R rhs;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
211 using char_type = typename L::char_type;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
212
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
213 template <typename OutputIt, typename... Args>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
214 constexpr OutputIt format(OutputIt out, const Args&... args) const {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
215 out = lhs.format(out, args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
216 return rhs.format(out, args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
217 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
218 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
219
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
220 template <typename L, typename R>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
221 struct is_compiled_format<concat<L, R>> : std::true_type {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
222
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
223 template <typename L, typename R>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
224 constexpr concat<L, R> make_concat(L lhs, R rhs) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
225 return {lhs, rhs};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
226 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
227
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
228 struct unknown_format {};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
229
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
230 template <typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
231 constexpr size_t parse_text(basic_string_view<Char> str, size_t pos) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
232 for (size_t size = str.size(); pos != size; ++pos) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
233 if (str[pos] == '{' || str[pos] == '}') break;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
234 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
235 return pos;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
236 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
237
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
238 template <typename Args, size_t POS, int ID, typename S>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
239 constexpr auto compile_format_string(S format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
240
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
241 template <typename Args, size_t POS, int ID, typename T, typename S>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
242 constexpr auto parse_tail(T head, S format_str) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
243 if constexpr (POS !=
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
244 basic_string_view<typename S::char_type>(format_str).size()) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
245 constexpr auto tail = compile_format_string<Args, POS, ID>(format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
246 if constexpr (std::is_same<remove_cvref_t<decltype(tail)>,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
247 unknown_format>())
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
248 return tail;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
249 else
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
250 return make_concat(head, tail);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
251 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
252 return head;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
253 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
254 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
255
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
256 template <typename T, typename Char> struct parse_specs_result {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
257 formatter<T, Char> fmt;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
258 size_t end;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
259 int next_arg_id;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
260 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
261
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
262 enum { manual_indexing_id = -1 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
263
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
264 template <typename T, typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
265 constexpr parse_specs_result<T, Char> parse_specs(basic_string_view<Char> str,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
266 size_t pos, int next_arg_id) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
267 str.remove_prefix(pos);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
268 auto ctx =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
269 compile_parse_context<Char>(str, max_value<int>(), nullptr, next_arg_id);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
270 auto f = formatter<T, Char>();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
271 auto end = f.parse(ctx);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
272 return {f, pos + fmt::detail::to_unsigned(end - str.data()),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
273 next_arg_id == 0 ? manual_indexing_id : ctx.next_arg_id()};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
274 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
275
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
276 template <typename Char> struct arg_id_handler {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
277 arg_ref<Char> arg_id;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
278
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
279 constexpr int on_auto() {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
280 FMT_ASSERT(false, "handler cannot be used with automatic indexing");
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
281 return 0;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
282 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
283 constexpr int on_index(int id) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
284 arg_id = arg_ref<Char>(id);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
285 return 0;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
286 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
287 constexpr int on_name(basic_string_view<Char> id) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
288 arg_id = arg_ref<Char>(id);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
289 return 0;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
290 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
291 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
292
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
293 template <typename Char> struct parse_arg_id_result {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
294 arg_ref<Char> arg_id;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
295 const Char* arg_id_end;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
296 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
297
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
298 template <int ID, typename Char>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
299 constexpr auto parse_arg_id(const Char* begin, const Char* end) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
300 auto handler = arg_id_handler<Char>{arg_ref<Char>{}};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
301 auto arg_id_end = parse_arg_id(begin, end, handler);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
302 return parse_arg_id_result<Char>{handler.arg_id, arg_id_end};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
303 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
304
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
305 template <typename T, typename Enable = void> struct field_type {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
306 using type = remove_cvref_t<T>;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
307 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
308
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
309 template <typename T>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
310 struct field_type<T, enable_if_t<detail::is_named_arg<T>::value>> {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
311 using type = remove_cvref_t<decltype(T::value)>;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
312 };
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
313
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
314 template <typename T, typename Args, size_t END_POS, int ARG_INDEX, int NEXT_ID,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
315 typename S>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
316 constexpr auto parse_replacement_field_then_tail(S format_str) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
317 using char_type = typename S::char_type;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
318 constexpr auto str = basic_string_view<char_type>(format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
319 constexpr char_type c = END_POS != str.size() ? str[END_POS] : char_type();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
320 if constexpr (c == '}') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
321 return parse_tail<Args, END_POS + 1, NEXT_ID>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
322 field<char_type, typename field_type<T>::type, ARG_INDEX>(),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
323 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
324 } else if constexpr (c != ':') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
325 FMT_THROW(format_error("expected ':'"));
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
326 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
327 constexpr auto result = parse_specs<typename field_type<T>::type>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
328 str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
329 if constexpr (result.end >= str.size() || str[result.end] != '}') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
330 FMT_THROW(format_error("expected '}'"));
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
331 return 0;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
332 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
333 return parse_tail<Args, result.end + 1, result.next_arg_id>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
334 spec_field<char_type, typename field_type<T>::type, ARG_INDEX>{
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
335 result.fmt},
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
336 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
337 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
338 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
339 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
340
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
341 // Compiles a non-empty format string and returns the compiled representation
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
342 // or unknown_format() on unrecognized input.
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
343 template <typename Args, size_t POS, int ID, typename S>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
344 constexpr auto compile_format_string(S format_str) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
345 using char_type = typename S::char_type;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
346 constexpr auto str = basic_string_view<char_type>(format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
347 if constexpr (str[POS] == '{') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
348 if constexpr (POS + 1 == str.size())
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
349 FMT_THROW(format_error("unmatched '{' in format string"));
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
350 if constexpr (str[POS + 1] == '{') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
351 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
352 } else if constexpr (str[POS + 1] == '}' || str[POS + 1] == ':') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
353 static_assert(ID != manual_indexing_id,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
354 "cannot switch from manual to automatic argument indexing");
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
355 constexpr auto next_id =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
356 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
357 return parse_replacement_field_then_tail<get_type<ID, Args>, Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
358 POS + 1, ID, next_id>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
359 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
360 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
361 constexpr auto arg_id_result =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
362 parse_arg_id<ID>(str.data() + POS + 1, str.data() + str.size());
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
363 constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
364 constexpr char_type c =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
365 arg_id_end_pos != str.size() ? str[arg_id_end_pos] : char_type();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
366 static_assert(c == '}' || c == ':', "missing '}' in format string");
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
367 if constexpr (arg_id_result.arg_id.kind == arg_id_kind::index) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
368 static_assert(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
369 ID == manual_indexing_id || ID == 0,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
370 "cannot switch from automatic to manual argument indexing");
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
371 constexpr auto arg_index = arg_id_result.arg_id.val.index;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
372 return parse_replacement_field_then_tail<get_type<arg_index, Args>,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
373 Args, arg_id_end_pos,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
374 arg_index, manual_indexing_id>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
375 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
376 } else if constexpr (arg_id_result.arg_id.kind == arg_id_kind::name) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
377 constexpr auto arg_index =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
378 get_arg_index_by_name(arg_id_result.arg_id.val.name, Args{});
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
379 if constexpr (arg_index >= 0) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
380 constexpr auto next_id =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
381 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
382 return parse_replacement_field_then_tail<
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
383 decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
384 arg_index, next_id>(format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
385 } else if constexpr (c == '}') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
386 return parse_tail<Args, arg_id_end_pos + 1, ID>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
387 runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
388 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
389 } else if constexpr (c == ':') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
390 return unknown_format(); // no type info for specs parsing
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
391 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
392 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
393 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
394 } else if constexpr (str[POS] == '}') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
395 if constexpr (POS + 1 == str.size())
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
396 FMT_THROW(format_error("unmatched '}' in format string"));
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
397 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
398 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
399 constexpr auto end = parse_text(str, POS + 1);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
400 if constexpr (end - POS > 1) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
401 return parse_tail<Args, end, ID>(make_text(str, POS, end - POS),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
402 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
403 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
404 return parse_tail<Args, end, ID>(code_unit<char_type>{str[POS]},
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
405 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
406 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
407 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
408 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
409
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
410 template <typename... Args, typename S,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
411 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
412 constexpr auto compile(S format_str) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
413 constexpr auto str = basic_string_view<typename S::char_type>(format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
414 if constexpr (str.size() == 0) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
415 return detail::make_text(str, 0, 0);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
416 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
417 constexpr auto result =
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
418 detail::compile_format_string<detail::type_list<Args...>, 0, 0>(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
419 format_str);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
420 return result;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
421 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
422 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
423 #endif // defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
424 } // namespace detail
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
425
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
426 FMT_BEGIN_EXPORT
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
427
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
428 #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
429
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
430 template <typename CompiledFormat, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
431 typename Char = typename CompiledFormat::char_type,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
432 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
433 FMT_INLINE std::basic_string<Char> format(const CompiledFormat& cf,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
434 const Args&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
435 auto s = std::basic_string<Char>();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
436 cf.format(std::back_inserter(s), args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
437 return s;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
438 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
439
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
440 template <typename OutputIt, typename CompiledFormat, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
441 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
442 constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
443 const Args&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
444 return cf.format(out, args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
445 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
446
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
447 template <typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
448 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
449 FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
450 Args&&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
451 if constexpr (std::is_same<typename S::char_type, char>::value) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
452 constexpr auto str = basic_string_view<typename S::char_type>(S());
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
453 if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
454 const auto& first = detail::first(args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
455 if constexpr (detail::is_named_arg<
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
456 remove_cvref_t<decltype(first)>>::value) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
457 return fmt::to_string(first.value);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
458 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
459 return fmt::to_string(first);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
460 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
461 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
462 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
463 constexpr auto compiled = detail::compile<Args...>(S());
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
464 if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
465 detail::unknown_format>()) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
466 return fmt::format(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
467 static_cast<basic_string_view<typename S::char_type>>(S()),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
468 std::forward<Args>(args)...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
469 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
470 return fmt::format(compiled, std::forward<Args>(args)...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
471 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
472 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
473
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
474 template <typename OutputIt, typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
475 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
476 FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
477 constexpr auto compiled = detail::compile<Args...>(S());
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
478 if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
479 detail::unknown_format>()) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
480 return fmt::format_to(
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
481 out, static_cast<basic_string_view<typename S::char_type>>(S()),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
482 std::forward<Args>(args)...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
483 } else {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
484 return fmt::format_to(out, compiled, std::forward<Args>(args)...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
485 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
486 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
487 #endif
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
488
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
489 template <typename OutputIt, typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
490 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
491 auto format_to_n(OutputIt out, size_t n, const S& format_str, Args&&... args)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
492 -> format_to_n_result<OutputIt> {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
493 using traits = detail::fixed_buffer_traits;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
494 auto buf = detail::iterator_buffer<OutputIt, char, traits>(out, n);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
495 fmt::format_to(std::back_inserter(buf), format_str,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
496 std::forward<Args>(args)...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
497 return {buf.out(), buf.count()};
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
498 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
499
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
500 template <typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
501 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
502 FMT_CONSTEXPR20 auto formatted_size(const S& format_str, const Args&... args)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
503 -> size_t {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
504 return fmt::format_to(detail::counting_iterator(), format_str, args...)
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
505 .count();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
506 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
507
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
508 template <typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
509 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
510 void print(std::FILE* f, const S& format_str, const Args&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
511 memory_buffer buffer;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
512 fmt::format_to(std::back_inserter(buffer), format_str, args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
513 detail::print(f, {buffer.data(), buffer.size()});
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
514 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
515
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
516 template <typename S, typename... Args,
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
517 FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
518 void print(const S& format_str, const Args&... args) {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
519 print(stdout, format_str, args...);
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
520 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
521
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
522 #if FMT_USE_NONTYPE_TEMPLATE_ARGS
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
523 inline namespace literals {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
524 template <detail_exported::fixed_string Str> constexpr auto operator""_cf() {
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
525 using char_t = remove_cvref_t<decltype(Str.data[0])>;
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
526 return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
527 Str>();
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
528 }
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
529 } // namespace literals
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
530 #endif
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
531
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
532 FMT_END_EXPORT
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
533 FMT_END_NAMESPACE
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
534
4aeffed717ef dep/fmt: add dependency
Paper <paper@paper.us.eu.org>
parents:
diff changeset
535 #endif // FMT_COMPILE_H_