SoPlex Documentation
Loading...
Searching...
No Matches
compile.h
Go to the documentation of this file.
1// Formatting library for C++ - experimental format string compilation
2//
3// Copyright (c) 2012 - present, Victor Zverovich and fmt contributors
4// All rights reserved.
5//
6// For the license information refer to format.h.
7
8#ifndef FMT_COMPILE_H_
9#define FMT_COMPILE_H_
10
11#include <vector>
12
13#include "format.h"
14
16namespace detail {
17
18// A compile-time string which is compiled into fast formatting code.
20
21template <typename S>
22struct is_compiled_string : std::is_base_of<compiled_string, S> {};
23
24/**
25 \rst
26 Converts a string literal *s* into a format string that will be parsed at
27 compile time and converted into efficient formatting code. Requires C++17
28 ``constexpr if`` compiler support.
29
30 **Example**::
31
32 // Converts 42 into std::string using the most efficient method and no
33 // runtime format string processing.
34 std::string s = fmt::format(FMT_COMPILE("{}"), 42);
35 \endrst
36 */
37#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string)
38
39template <typename T, typename... Tail>
40const T& first(const T& value, const Tail&...) {
41 return value;
42}
43
44// Part of a compiled format string. It can be either literal text or a
45// replacement field.
83
84template <typename Char> struct part_counter {
85 unsigned num_parts = 0;
86
87 FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
88 if (begin != end) ++num_parts;
89 }
90
91 FMT_CONSTEXPR int on_arg_id() { return ++num_parts, 0; }
92 FMT_CONSTEXPR int on_arg_id(int) { return ++num_parts, 0; }
96
97 FMT_CONSTEXPR void on_replacement_field(int, const Char*) {}
98
99 FMT_CONSTEXPR const Char* on_format_specs(int, const Char* begin,
100 const Char* end) {
101 // Find the matching brace.
102 unsigned brace_counter = 0;
103 for (; begin != end; ++begin) {
104 if (*begin == '{') {
105 ++brace_counter;
106 } else if (*begin == '}') {
107 if (brace_counter == 0u) break;
108 --brace_counter;
109 }
110 }
111 return begin;
112 }
113
114 FMT_CONSTEXPR void on_error(const char*) {}
115};
116
117// Counts the number of parts in a format string.
118template <typename Char>
120 part_counter<Char> counter;
121 parse_format_string<true>(format_str, counter);
122 return counter.num_parts;
123}
124
125template <typename Char, typename PartHandler>
127 private:
129
130 PartHandler handler_;
134
135 public:
137 PartHandler handler)
138 : handler_(handler),
139 format_str_(format_str),
140 parse_context_(format_str) {}
141
142 FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
143 if (begin != end)
144 handler_(part::make_text({begin, to_unsigned(end - begin)}));
145 }
146
149 return 0;
150 }
151
153 parse_context_.check_arg_id(id);
155 return 0;
156 }
157
162
163 FMT_CONSTEXPR void on_replacement_field(int, const Char* ptr) {
166 }
167
168 FMT_CONSTEXPR const Char* on_format_specs(int, const Char* begin,
169 const Char* end) {
170 auto repl = typename part::replacement();
172 repl.specs, parse_context_);
173 auto it = parse_format_specs(begin, end, handler);
174 if (*it != '}') on_error("missing '}' in format string");
175 repl.arg_id = part_.part_kind == part::kind::arg_index
178 auto part = part::make_replacement(repl);
179 part.arg_id_end = begin;
180 handler_(part);
181 return it;
182 }
183};
184
185// Compiles a format string and invokes handler(part) for each parsed part.
186template <bool IS_CONSTEXPR, typename Char, typename PartHandler>
188 PartHandler handler) {
190 format_str,
191 format_string_compiler<Char, PartHandler>(format_str, handler));
192}
193
194template <typename OutputIt, typename Context, typename Id>
197 Context& ctx, Id arg_id) {
198 ctx.advance_to(visit_format_arg(
200 ctx.arg(arg_id)));
201}
202
203// vformat_to is defined in a subnamespace to prevent ADL.
204namespace cf {
205template <typename Context, typename OutputIt, typename CompiledFormat>
206auto vformat_to(OutputIt out, CompiledFormat& cf,
207 basic_format_args<Context> args) -> typename Context::iterator {
208 using char_type = typename Context::char_type;
210 to_string_view(cf.format_str_));
211 Context ctx(out, args);
212
213 const auto& parts = cf.parts();
214 for (auto part_it = std::begin(parts); part_it != std::end(parts);
215 ++part_it) {
216 const auto& part = *part_it;
217 const auto& value = part.val;
218
219 using format_part_t = format_part<char_type>;
220 switch (part.part_kind) {
221 case format_part_t::kind::text: {
222 const auto text = value.str;
223 auto output = ctx.out();
224 auto&& it = reserve(output, text.size());
225 it = std::copy_n(text.begin(), text.size(), it);
226 ctx.advance_to(output);
227 break;
228 }
229
230 case format_part_t::kind::arg_index:
231 advance_to(parse_ctx, part.arg_id_end);
232 detail::format_arg<OutputIt>(parse_ctx, ctx, value.arg_index);
233 break;
234
235 case format_part_t::kind::arg_name:
236 advance_to(parse_ctx, part.arg_id_end);
237 detail::format_arg<OutputIt>(parse_ctx, ctx, value.str);
238 break;
239
240 case format_part_t::kind::replacement: {
241 const auto& arg_id_value = value.repl.arg_id.val;
242 const auto arg = value.repl.arg_id.kind == arg_id_kind::index
243 ? ctx.arg(arg_id_value.index)
244 : ctx.arg(arg_id_value.name);
245
246 auto specs = value.repl.specs;
247
248 handle_dynamic_spec<width_checker>(specs.width, specs.width_ref, ctx);
250 specs.precision_ref, ctx);
251
253 numeric_specs_checker<error_handler> checker(h, arg.type());
254 if (specs.align == align::numeric) checker.require_numeric_argument();
255 if (specs.sign != sign::none) checker.check_sign();
256 if (specs.alt) checker.require_numeric_argument();
257 if (specs.precision >= 0) checker.check_precision();
258
259 advance_to(parse_ctx, part.arg_id_end);
260 ctx.advance_to(
262 ctx, nullptr, &specs),
263 arg));
264 break;
265 }
266 }
267 }
268 return ctx.out();
269}
270} // namespace cf
271
273
274template <typename S, typename = void>
277 using parts_container = std::vector<detail::format_part<char_type>>;
278
280
283 [this](const format_part<char_type>& part) {
284 compiled_parts.push_back(part);
285 });
286 }
287
288 const parts_container& parts() const { return compiled_parts; }
289};
290
291template <typename Char, unsigned N> struct format_part_array {
294};
295
296template <typename Char, unsigned N>
298 basic_string_view<Char> format_str) {
300 unsigned counter = 0;
301 // This is not a lambda for compatibility with older compilers.
302 struct {
303 format_part<Char>* parts;
304 unsigned* counter;
305 FMT_CONSTEXPR void operator()(const format_part<Char>& part) {
306 parts[(*counter)++] = part;
307 }
308 } collector{parts.data, &counter};
309 compile_format_string<true>(format_str, collector);
310 if (counter < N) {
311 parts.data[counter] =
313 }
314 return parts;
315}
316
317template <typename T> constexpr const T& constexpr_max(const T& a, const T& b) {
318 return (a < b) ? b : a;
319}
320
321template <typename S>
325
327
328// Workaround for old compilers. Format string compilation will not be
329// performed there anyway.
330#if FMT_USE_CONSTEXPR
331 static FMT_CONSTEXPR_DECL const unsigned num_format_parts =
333#else
334 static const unsigned num_format_parts = 1;
335#endif
336
337 using parts_container = format_part<char_type>[num_format_parts];
338
339 const parts_container& parts() const {
340 static FMT_CONSTEXPR_DECL const auto compiled_parts =
342 detail::to_string_view(S()));
343 return compiled_parts.data;
344 }
345};
346
347template <typename S, typename... Args>
349 public:
351
352 private:
354
355 template <typename Context, typename OutputIt, typename CompiledFormat>
356 friend auto cf::vformat_to(OutputIt out, CompiledFormat& cf,
358 typename Context::iterator;
359
360 public:
361 compiled_format() = delete;
362 explicit constexpr compiled_format(basic_string_view<char_type> format_str)
363 : compiled_format_base<S>(format_str), format_str_(format_str) {}
364};
365
366#ifdef __cpp_if_constexpr
367template <typename... Args> struct type_list {};
368
369// Returns a reference to the argument at index N from [first, rest...].
370template <int N, typename T, typename... Args>
371constexpr const auto& get([[maybe_unused]] const T& first,
372 [[maybe_unused]] const Args&... rest) {
373 static_assert(N < 1 + sizeof...(Args), "index is out of bounds");
374 if constexpr (N == 0)
375 return first;
376 else
377 return get<N - 1>(rest...);
378}
379
380template <int N, typename> struct get_type_impl;
381
382template <int N, typename... Args> struct get_type_impl<N, type_list<Args...>> {
383 using type = remove_cvref_t<decltype(get<N>(std::declval<Args>()...))>;
384};
385
386template <int N, typename T>
387using get_type = typename get_type_impl<N, T>::type;
388
389template <typename T> struct is_compiled_format : std::false_type {};
390
391template <typename Char> struct text {
393 using char_type = Char;
394
395 template <typename OutputIt, typename... Args>
396 OutputIt format(OutputIt out, const Args&...) const {
397 return write<Char>(out, data);
398 }
399};
400
401template <typename Char>
402struct is_compiled_format<text<Char>> : std::true_type {};
403
404template <typename Char>
405constexpr text<Char> make_text(basic_string_view<Char> s, size_t pos,
406 size_t size) {
407 return {{&s[pos], size}};
408}
409
410template <typename Char> struct code_unit {
411 Char value;
412 using char_type = Char;
413
414 template <typename OutputIt, typename... Args>
415 OutputIt format(OutputIt out, const Args&...) const {
416 return write<Char>(out, value);
417 }
418};
419
420template <typename Char>
421struct is_compiled_format<code_unit<Char>> : std::true_type {};
422
423// A replacement field that refers to argument N.
424template <typename Char, typename T, int N> struct field {
425 using char_type = Char;
426
427 template <typename OutputIt, typename... Args>
428 OutputIt format(OutputIt out, const Args&... args) const {
429 // This ensures that the argument type is convertile to `const T&`.
430 const T& arg = get<N>(args...);
431 return write<Char>(out, arg);
432 }
433};
434
435template <typename Char, typename T, int N>
436struct is_compiled_format<field<Char, T, N>> : std::true_type {};
437
438// A replacement field that refers to argument N and has format specifiers.
439template <typename Char, typename T, int N> struct spec_field {
440 using char_type = Char;
441 mutable formatter<T, Char> fmt;
442
443 template <typename OutputIt, typename... Args>
444 OutputIt format(OutputIt out, const Args&... args) const {
445 // This ensures that the argument type is convertile to `const T&`.
446 const T& arg = get<N>(args...);
447 const auto& vargs =
450 return fmt.format(arg, ctx);
451 }
452};
453
454template <typename Char, typename T, int N>
455struct is_compiled_format<spec_field<Char, T, N>> : std::true_type {};
456
457template <typename L, typename R> struct concat {
458 L lhs;
459 R rhs;
460 using char_type = typename L::char_type;
461
462 template <typename OutputIt, typename... Args>
463 OutputIt format(OutputIt out, const Args&... args) const {
464 out = lhs.format(out, args...);
465 return rhs.format(out, args...);
466 }
467};
468
469template <typename L, typename R>
470struct is_compiled_format<concat<L, R>> : std::true_type {};
471
472template <typename L, typename R>
473constexpr concat<L, R> make_concat(L lhs, R rhs) {
474 return {lhs, rhs};
475}
476
477struct unknown_format {};
478
479template <typename Char>
480constexpr size_t parse_text(basic_string_view<Char> str, size_t pos) {
481 for (size_t size = str.size(); pos != size; ++pos) {
482 if (str[pos] == '{' || str[pos] == '}') break;
483 }
484 return pos;
485}
486
487template <typename Args, size_t POS, int ID, typename S>
488constexpr auto compile_format_string(S format_str);
489
490template <typename Args, size_t POS, int ID, typename T, typename S>
491constexpr auto parse_tail(T head, S format_str) {
492 if constexpr (POS !=
494 constexpr auto tail = compile_format_string<Args, POS, ID>(format_str);
495 if constexpr (std::is_same<remove_cvref_t<decltype(tail)>,
496 unknown_format>())
497 return tail;
498 else
499 return make_concat(head, tail);
500 } else {
501 return head;
502 }
503}
504
505template <typename T, typename Char> struct parse_specs_result {
507 size_t end;
508 int next_arg_id;
509};
510
511template <typename T, typename Char>
512constexpr parse_specs_result<T, Char> parse_specs(basic_string_view<Char> str,
513 size_t pos, int arg_id) {
514 str.remove_prefix(pos);
515 auto ctx = basic_format_parse_context<Char>(str, {}, arg_id + 1);
516 auto f = formatter<T, Char>();
517 auto end = f.parse(ctx);
518 return {f, pos + (end - str.data()) + 1, ctx.next_arg_id()};
519}
520
521// Compiles a non-empty format string and returns the compiled representation
522// or unknown_format() on unrecognized input.
523template <typename Args, size_t POS, int ID, typename S>
524constexpr auto compile_format_string(S format_str) {
525 using char_type = typename S::char_type;
526 constexpr basic_string_view<char_type> str = format_str;
527 if constexpr (str[POS] == '{') {
528 if (POS + 1 == str.size())
529 throw format_error("unmatched '{' in format string");
530 if constexpr (str[POS + 1] == '{') {
531 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
532 } else if constexpr (str[POS + 1] == '}') {
533 using type = get_type<ID, Args>;
534 return parse_tail<Args, POS + 2, ID + 1>(field<char_type, type, ID>(),
535 format_str);
536 } else if constexpr (str[POS + 1] == ':') {
537 using type = get_type<ID, Args>;
538 constexpr auto result = parse_specs<type>(str, POS + 2, ID);
539 return parse_tail<Args, result.end, result.next_arg_id>(
540 spec_field<char_type, type, ID>{result.fmt}, format_str);
541 } else {
542 return unknown_format();
543 }
544 } else if constexpr (str[POS] == '}') {
545 if (POS + 1 == str.size())
546 throw format_error("unmatched '}' in format string");
547 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
548 } else {
549 constexpr auto end = parse_text(str, POS + 1);
550 if constexpr (end - POS > 1) {
551 return parse_tail<Args, end, ID>(make_text(str, POS, end - POS),
552 format_str);
553 } else {
554 return parse_tail<Args, end, ID>(code_unit<char_type>{str[POS]},
555 format_str);
556 }
557 }
558}
559
560template <typename... Args, typename S,
563constexpr auto compile(S format_str) {
564 constexpr basic_string_view<typename S::char_type> str = format_str;
565 if constexpr (str.size() == 0) {
566 return detail::make_text(str, 0, 0);
567 } else {
568 constexpr auto result =
569 detail::compile_format_string<detail::type_list<Args...>, 0, 0>(
570 format_str);
571 if constexpr (std::is_same<remove_cvref_t<decltype(result)>,
572 detail::unknown_format>()) {
573 return detail::compiled_format<S, Args...>(to_string_view(format_str));
574 } else {
575 return result;
576 }
577 }
578}
579#else
580template <typename... Args, typename S,
582constexpr auto compile(S format_str) -> detail::compiled_format<S, Args...> {
583 return detail::compiled_format<S, Args...>(to_string_view(format_str));
584}
585#endif // __cpp_if_constexpr
586
587// Compiles the format string which must be a string literal.
588template <typename... Args, typename Char, size_t N>
589auto compile(const Char (&format_str)[N])
590 -> detail::compiled_format<const Char*, Args...> {
591 return detail::compiled_format<const Char*, Args...>(
592 basic_string_view<Char>(format_str, N - 1));
593}
594} // namespace detail
595
596// DEPRECATED! use FMT_COMPILE instead.
597template <typename... Args>
598FMT_DEPRECATED auto compile(const Args&... args)
599 -> decltype(detail::compile(args...)) {
600 return detail::compile(args...);
601}
602
603#if FMT_USE_CONSTEXPR
604# ifdef __cpp_if_constexpr
605
606template <typename CompiledFormat, typename... Args,
607 typename Char = typename CompiledFormat::char_type,
608 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
609FMT_INLINE std::basic_string<Char> format(const CompiledFormat& cf,
610 const Args&... args) {
612 cf.format(detail::buffer_appender<Char>(buffer), args...);
613 return to_string(buffer);
614}
615
616template <typename OutputIt, typename CompiledFormat, typename... Args,
617 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
618OutputIt format_to(OutputIt out, const CompiledFormat& cf,
619 const Args&... args) {
620 return cf.format(out, args...);
621}
622# endif // __cpp_if_constexpr
623#endif // FMT_USE_CONSTEXPR
624
625template <typename CompiledFormat, typename... Args,
626 typename Char = typename CompiledFormat::char_type,
628 CompiledFormat>::value)>
629std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
631 using context = buffer_context<Char>;
634 return to_string(buffer);
635}
636
637template <typename S, typename... Args,
639FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
640 Args&&... args) {
641#ifdef __cpp_if_constexpr
642 if constexpr (std::is_same<typename S::char_type, char>::value) {
644 if (str.size() == 2 && str[0] == '{' && str[1] == '}')
645 return fmt::to_string(detail::first(args...));
646 }
647#endif
648 constexpr auto compiled = detail::compile<Args...>(S());
649 return format(compiled, std::forward<Args>(args)...);
650}
651
652template <typename OutputIt, typename CompiledFormat, typename... Args,
654 CompiledFormat>::value)>
655OutputIt format_to(OutputIt out, const CompiledFormat& cf,
656 const Args&... args) {
657 using char_type = typename CompiledFormat::char_type;
659 return detail::cf::vformat_to<context>(out, cf,
661}
662
663template <typename OutputIt, typename S, typename... Args,
665OutputIt format_to(OutputIt out, const S&, const Args&... args) {
666 constexpr auto compiled = detail::compile<Args...>(S());
667 return format_to(out, compiled, args...);
668}
669
670template <typename OutputIt, typename CompiledFormat, typename... Args>
671auto format_to_n(OutputIt out, size_t n, const CompiledFormat& cf,
672 const Args&... args) ->
673 typename std::enable_if<
675 typename CompiledFormat::char_type>::value &&
676 std::is_base_of<detail::basic_compiled_format,
677 CompiledFormat>::value,
679 auto it =
681 return {it.base(), it.count()};
682}
683
684template <typename OutputIt, typename S, typename... Args,
686format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n, const S&,
687 const Args&... args) {
688 constexpr auto compiled = detail::compile<Args...>(S());
689 auto it = format_to(detail::truncating_iterator<OutputIt>(out, n), compiled,
690 args...);
691 return {it.base(), it.count()};
692}
693
694template <typename CompiledFormat, typename... Args>
695size_t formatted_size(const CompiledFormat& cf, const Args&... args) {
696 return format_to(detail::counting_iterator(), cf, args...).count();
697}
698
700
701#endif // FMT_COMPILE_H_
FMT_CONSTEXPR int next_arg_id()
Definition core.h:593
FMT_CONSTEXPR void remove_prefix(size_t n)
Definition core.h:406
constexpr size_t size() const
Definition core.h:399
constexpr const Char * data() const
Definition core.h:396
constexpr compiled_format(basic_string_view< char_type > format_str)
Definition compile.h:362
basic_string_view< char_type > format_str_
Definition compile.h:353
FMT_CONSTEXPR void on_text(const Char *begin, const Char *end)
Definition compile.h:142
FMT_CONSTEXPR format_string_compiler(basic_string_view< Char > format_str, PartHandler handler)
Definition compile.h:136
FMT_CONSTEXPR int on_arg_id()
Definition compile.h:147
basic_string_view< Char > format_str_
Definition compile.h:132
FMT_CONSTEXPR int on_arg_id(int id)
Definition compile.h:152
FMT_CONSTEXPR int on_arg_id(basic_string_view< Char > id)
Definition compile.h:158
FMT_CONSTEXPR const Char * on_format_specs(int, const Char *begin, const Char *end)
Definition compile.h:168
basic_format_parse_context< Char > parse_context_
Definition compile.h:133
FMT_CONSTEXPR void on_replacement_field(int, const Char *ptr)
Definition compile.h:163
FMT_CONSTEXPR void require_numeric_argument()
Definition format.h:2476
FMT_CONSTEXPR void check_sign()
Definition format.h:2481
FMT_CONSTEXPR void check_precision()
Definition format.h:2489
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:560
auto format_to_n(OutputIt out, size_t n, const CompiledFormat &cf, const Args &... args) -> typename std::enable_if< detail::is_output_iterator< OutputIt, typename CompiledFormat::char_type >::value &&std::is_base_of< detail::basic_compiled_format, CompiledFormat >::value, format_to_n_result< OutputIt > >::type
Definition compile.h:671
std::basic_string< Char > format(const CompiledFormat &cf, const Args &... args)
Definition compile.h:629
size_t formatted_size(const CompiledFormat &cf, const Args &... args)
Definition compile.h:695
OutputIt format_to(OutputIt out, const CompiledFormat &cf, const Args &... args)
Definition compile.h:655
FMT_DEPRECATED auto compile(const Args &... args) -> decltype(detail::compile(args...))
Definition compile.h:598
typename std::enable_if< B, T >::type enable_if_t
Definition core.h:259
typename detail::char_t_impl< S >::type char_t
Definition core.h:540
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
Definition core.h:1640
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition core.h:268
#define FMT_CONSTEXPR
Definition core.h:98
format_arg_store< Context, Args... > make_format_args(const Args &... args)
Definition core.h:1603
#define FMT_BEGIN_NAMESPACE
Definition core.h:203
#define FMT_DEPRECATED
Definition core.h:161
#define FMT_ENABLE_IF(...)
Definition core.h:277
#define FMT_INLINE
Definition core.h:177
FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition core.h:1310
#define FMT_END_NAMESPACE
Definition core.h:198
#define FMT_CONSTEXPR_DECL
Definition core.h:99
const void * ptr(const T *p)
Definition format.h:3603
FMT_CONSTEXPR void advance_to(basic_format_parse_context< Char, ErrorHandler > &ctx, const Char *p)
Definition format.h:3589
std::string to_string(const T &value)
Definition format.h:3730
@ numeric
Definition format.h:1175
auto vformat_to(OutputIt out, CompiledFormat &cf, basic_format_args< Context > args) -> typename Context::iterator
Definition compile.h:206
checked_ptr< typename Container::value_type > reserve(std::back_insert_iterator< Container > it, size_t n)
Definition format.h:373
FMT_CONSTEXPR_DECL FMT_INLINE void parse_format_string(basic_string_view< Char > format_str, Handler &&handler)
Definition format.h:2986
FMT_CONSTEXPR format_part_array< Char, N > compile_to_parts(basic_string_view< Char > format_str)
Definition compile.h:297
void to_string_view(...)
FMT_CONSTEXPR const Char * parse_format_specs(const Char *begin, const Char *end, SpecHandler &&handler)
Definition format.h:2879
const T & first(const T &value, const Tail &...)
Definition compile.h:40
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition core.h:325
FMT_CONSTEXPR void compile_format_string(basic_string_view< Char > format_str, PartHandler handler)
Definition compile.h:187
void format_arg(basic_format_parse_context< typename Context::char_type > &parse_ctx, Context &ctx, Id arg_id)
Definition compile.h:195
type
Definition core.h:977
constexpr const T & constexpr_max(const T &a, const T &b)
Definition compile.h:317
constexpr auto compile(S format_str) -> detail::compiled_format< S, Args... >
Definition compile.h:582
void handle_dynamic_spec(int &value, arg_ref< typename Context::char_type > ref, Context &ctx)
Definition format.h:3233
FMT_CONSTEXPR unsigned count_parts(basic_string_view< Char > format_str)
Definition compile.h:119
@ none
Definition format.h:1180
FMT_CONSTEXPR compiled_format_base(basic_string_view< char_type >)
Definition compile.h:326
std::vector< detail::format_part< char_type > > parts_container
Definition compile.h:277
parts_container compiled_parts
Definition compile.h:279
compiled_format_base(basic_string_view< char_type > format_str)
Definition compile.h:281
const parts_container & parts() const
Definition compile.h:288
FMT_NORETURN FMT_API void on_error(const char *message)
dynamic_format_specs< Char > specs
Definition compile.h:51
format_part< Char > data[N]
Definition compile.h:292
FMT_CONSTEXPR format_part_array()=default
static FMT_CONSTEXPR format_part make_arg_index(int index)
Definition compile.h:70
static FMT_CONSTEXPR format_part make_text(basic_string_view< Char > text)
Definition compile.h:76
FMT_CONSTEXPR format_part(kind k=kind::arg_index, value v={})
Definition compile.h:67
union detail::format_part::value val
static FMT_CONSTEXPR format_part make_arg_name(basic_string_view< Char > name)
Definition compile.h:73
const Char * arg_id_end
Definition compile.h:65
static FMT_CONSTEXPR format_part make_replacement(replacement repl)
Definition compile.h:79
FMT_CONSTEXPR void on_text(const Char *begin, const Char *end)
Definition compile.h:87
unsigned num_parts
Definition compile.h:85
FMT_CONSTEXPR void on_replacement_field(int, const Char *)
Definition compile.h:97
FMT_CONSTEXPR int on_arg_id()
Definition compile.h:91
FMT_CONSTEXPR void on_error(const char *)
Definition compile.h:114
FMT_CONSTEXPR int on_arg_id(basic_string_view< Char >)
Definition compile.h:93
FMT_CONSTEXPR int on_arg_id(int)
Definition compile.h:92
FMT_CONSTEXPR const Char * on_format_specs(int, const Char *begin, const Char *end)
Definition compile.h:99
FMT_CONSTEXPR value(basic_string_view< Char > s)
Definition compile.h:61
FMT_CONSTEXPR value(int index=0)
Definition compile.h:60
FMT_CONSTEXPR value(replacement r)
Definition compile.h:62
basic_string_view< Char > str
Definition compile.h:57