SoPlex Documentation
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1// Formatting library for C++ - the core API
2//
3// Copyright (c) 2012 - present, Victor Zverovich
4// All rights reserved.
5//
6// For the license information refer to format.h.
7
8#ifndef FMT_CORE_H_
9#define FMT_CORE_H_
10
11#include <cstdio> // std::FILE
12#include <cstring>
13#include <iterator>
14#include <string>
15#include <type_traits>
16
17// The fmt library version in the form major * 10000 + minor * 100 + patch.
18#define FMT_VERSION 60102
19
20#ifdef __has_feature
21# define FMT_HAS_FEATURE(x) __has_feature(x)
22#else
23# define FMT_HAS_FEATURE(x) 0
24#endif
25
26#if defined(__has_include) && !defined(__INTELLISENSE__) && \
27 !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600)
28# define FMT_HAS_INCLUDE(x) __has_include(x)
29#else
30# define FMT_HAS_INCLUDE(x) 0
31#endif
32
33#ifdef __has_cpp_attribute
34# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
35#else
36# define FMT_HAS_CPP_ATTRIBUTE(x) 0
37#endif
38
39#if defined(__GNUC__) && !defined(__clang__)
40# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
41#else
42# define FMT_GCC_VERSION 0
43#endif
44
45#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
46# define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION
47#else
48# define FMT_HAS_GXX_CXX11 0
49#endif
50
51#ifdef __NVCC__
52# define FMT_NVCC __NVCC__
53#else
54# define FMT_NVCC 0
55#endif
56
57#ifdef _MSC_VER
58# define FMT_MSC_VER _MSC_VER
59#else
60# define FMT_MSC_VER 0
61#endif
62
63// Check if relaxed C++14 constexpr is supported.
64// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
65#ifndef FMT_USE_CONSTEXPR
66# define FMT_USE_CONSTEXPR \
67 (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \
68 (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \
69 !FMT_NVCC
70#endif
71#if FMT_USE_CONSTEXPR
72# define FMT_CONSTEXPR constexpr
73# define FMT_CONSTEXPR_DECL constexpr
74#else
75# define FMT_CONSTEXPR inline
76# define FMT_CONSTEXPR_DECL
77#endif
78
79#ifndef FMT_OVERRIDE
80# if FMT_HAS_FEATURE(cxx_override) || \
81 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
82# define FMT_OVERRIDE override
83# else
84# define FMT_OVERRIDE
85# endif
86#endif
87
88// Check if exceptions are disabled.
89#ifndef FMT_EXCEPTIONS
90# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
91 FMT_MSC_VER && !_HAS_EXCEPTIONS
92# define FMT_EXCEPTIONS 0
93# else
94# define FMT_EXCEPTIONS 1
95# endif
96#endif
97
98// Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature).
99#ifndef FMT_USE_NOEXCEPT
100# define FMT_USE_NOEXCEPT 0
101#endif
102
103#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
104 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
105# define FMT_DETECTED_NOEXCEPT noexcept
106# define FMT_HAS_CXX11_NOEXCEPT 1
107#else
108# define FMT_DETECTED_NOEXCEPT throw()
109# define FMT_HAS_CXX11_NOEXCEPT 0
110#endif
111
112#ifndef FMT_NOEXCEPT
113# if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT
114# define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT
115# else
116# define FMT_NOEXCEPT
117# endif
118#endif
119
120// [[noreturn]] is disabled on MSVC because of bogus unreachable code warnings.
121#if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VER
122# define FMT_NORETURN [[noreturn]]
123#else
124# define FMT_NORETURN
125#endif
126
127#ifndef FMT_DEPRECATED
128# if (FMT_HAS_CPP_ATTRIBUTE(deprecated) && __cplusplus >= 201402L) || \
129 FMT_MSC_VER >= 1900
130# define FMT_DEPRECATED [[deprecated]]
131# else
132# if defined(__GNUC__) || defined(__clang__)
133# define FMT_DEPRECATED __attribute__((deprecated))
134# elif FMT_MSC_VER
135# define FMT_DEPRECATED __declspec(deprecated)
136# else
137# define FMT_DEPRECATED /* deprecated */
138# endif
139# endif
140#endif
141
142// Workaround broken [[deprecated]] in the Intel compiler and NVCC.
143#if defined(__INTEL_COMPILER) || FMT_NVCC
144# define FMT_DEPRECATED_ALIAS
145#else
146# define FMT_DEPRECATED_ALIAS FMT_DEPRECATED
147#endif
148
149#ifndef FMT_BEGIN_NAMESPACE
150# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \
151 FMT_MSC_VER >= 1900
152# define FMT_INLINE_NAMESPACE inline namespace
153# define FMT_END_NAMESPACE \
154 } \
155 }
156# else
157# define FMT_INLINE_NAMESPACE namespace
158# define FMT_END_NAMESPACE \
159 } \
160 using namespace v6; \
161 }
162# endif
163# define FMT_BEGIN_NAMESPACE \
164 namespace fmt { \
165 FMT_INLINE_NAMESPACE v6 {
166#endif
167
168#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
169# ifdef FMT_EXPORT
170# define FMT_API __declspec(dllexport)
171# elif defined(FMT_SHARED)
172# define FMT_API __declspec(dllimport)
173# define FMT_EXTERN_TEMPLATE_API FMT_API
174# endif
175#endif
176#ifndef FMT_API
177# define FMT_API
178#endif
179#ifndef FMT_EXTERN_TEMPLATE_API
180# define FMT_EXTERN_TEMPLATE_API
181#endif
182
183#ifndef FMT_HEADER_ONLY
184# define FMT_EXTERN extern
185#else
186# define FMT_EXTERN
187#endif
188
189// libc++ supports string_view in pre-c++17.
190#if (FMT_HAS_INCLUDE(<string_view>) && \
191 (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
192 (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
193# include <string_view>
194# define FMT_USE_STRING_VIEW
195#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
196# include <experimental/string_view>
197# define FMT_USE_EXPERIMENTAL_STRING_VIEW
198#endif
199
201
202// Implementations of enable_if_t and other types for pre-C++14 systems.
203template <bool B, class T = void>
204using enable_if_t = typename std::enable_if<B, T>::type;
205template <bool B, class T, class F>
206using conditional_t = typename std::conditional<B, T, F>::type;
207template <bool B> using bool_constant = std::integral_constant<bool, B>;
208template <typename T>
209using remove_reference_t = typename std::remove_reference<T>::type;
210template <typename T>
211using remove_const_t = typename std::remove_const<T>::type;
212template <typename T>
213using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
214
215struct monostate {};
216
217// An enable_if helper to be used in template parameters which results in much
218// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
219// to workaround a bug in MSVC 2019 (see #1140 and #1186).
220#define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
221
222namespace internal {
223
224// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
225template <typename... Ts> struct void_t_impl { using type = void; };
226
227FMT_API void assert_fail(const char* file, int line, const char* message);
228
229#ifndef FMT_ASSERT
230# ifdef NDEBUG
231# define FMT_ASSERT(condition, message)
232# else
233# define FMT_ASSERT(condition, message) \
234 ((condition) \
235 ? void() \
236 : fmt::internal::assert_fail(__FILE__, __LINE__, (message)))
237# endif
238#endif
239
240#if defined(FMT_USE_STRING_VIEW)
241template <typename Char> using std_string_view = std::basic_string_view<Char>;
242#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
243template <typename Char>
244using std_string_view = std::experimental::basic_string_view<Char>;
245#else
246template <typename T> struct std_string_view {};
247#endif
248
249#ifdef FMT_USE_INT128
250// Do nothing.
251#elif defined(__SIZEOF_INT128__)
252# define FMT_USE_INT128 1
253using int128_t = __int128_t;
254using uint128_t = __uint128_t;
255#else
256# define FMT_USE_INT128 0
257#endif
258#if !FMT_USE_INT128
259struct int128_t {};
260struct uint128_t {};
261#endif
262
263// Casts a nonnegative integer to unsigned.
264template <typename Int>
265FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
266 FMT_ASSERT(value >= 0, "negative value");
267 return static_cast<typename std::make_unsigned<Int>::type>(value);
268}
269} // namespace internal
270
271template <typename... Ts>
272using void_t = typename internal::void_t_impl<Ts...>::type;
273
274/**
275 An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
276 subset of the API. ``fmt::basic_string_view`` is used for format strings even
277 if ``std::string_view`` is available to prevent issues when a library is
278 compiled with a different ``-std`` option than the client code (which is not
279 recommended).
280 */
281template <typename Char> class basic_string_view {
282 private:
283 const Char* data_;
284 size_t size_;
285
286 public:
287 using char_type = Char;
288 using iterator = const Char*;
289
291
292 /** Constructs a string reference object from a C string and a size. */
293 FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
294 : data_(s),
295 size_(count) {}
296
297 /**
298 \rst
299 Constructs a string reference object from a C string computing
300 the size with ``std::char_traits<Char>::length``.
301 \endrst
302 */
303 basic_string_view(const Char* s)
304 : data_(s), size_(std::char_traits<Char>::length(s)) {}
305
306 /** Constructs a string reference from a ``std::basic_string`` object. */
307 template <typename Traits, typename Alloc>
309 const std::basic_string<Char, Traits, Alloc>& s) FMT_NOEXCEPT
310 : data_(s.data()),
311 size_(s.size()) {}
312
313 template <
314 typename S,
315 FMT_ENABLE_IF(std::is_same<S, internal::std_string_view<Char>>::value)>
317 size_(s.size()) {}
318
319 /** Returns a pointer to the string data. */
320 FMT_CONSTEXPR const Char* data() const { return data_; }
321
322 /** Returns the string size. */
323 FMT_CONSTEXPR size_t size() const { return size_; }
324
325 FMT_CONSTEXPR iterator begin() const { return data_; }
326 FMT_CONSTEXPR iterator end() const { return data_ + size_; }
327
328 FMT_CONSTEXPR const Char& operator[](size_t pos) const { return data_[pos]; }
329
331 data_ += n;
332 size_ -= n;
333 }
334
335 // Lexicographically compare this string reference to other.
336 int compare(basic_string_view other) const {
337 size_t str_size = size_ < other.size_ ? size_ : other.size_;
338 int result = std::char_traits<Char>::compare(data_, other.data_, str_size);
339 if (result == 0)
340 result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
341 return result;
342 }
343
345 return lhs.compare(rhs) == 0;
346 }
348 return lhs.compare(rhs) != 0;
349 }
351 return lhs.compare(rhs) < 0;
352 }
354 return lhs.compare(rhs) <= 0;
355 }
357 return lhs.compare(rhs) > 0;
358 }
360 return lhs.compare(rhs) >= 0;
361 }
362};
363
366
367#ifndef __cpp_char8_t
368// A UTF-8 code unit type.
369enum char8_t : unsigned char {};
370#endif
371
372/** Specifies if ``T`` is a character type. Can be specialized by users. */
373template <typename T> struct is_char : std::false_type {};
374template <> struct is_char<char> : std::true_type {};
375template <> struct is_char<wchar_t> : std::true_type {};
376template <> struct is_char<char8_t> : std::true_type {};
377template <> struct is_char<char16_t> : std::true_type {};
378template <> struct is_char<char32_t> : std::true_type {};
379
380/**
381 \rst
382 Returns a string view of `s`. In order to add custom string type support to
383 {fmt} provide an overload of `to_string_view` for it in the same namespace as
384 the type for the argument-dependent lookup to work.
385
386 **Example**::
387
388 namespace my_ns {
389 inline string_view to_string_view(const my_string& s) {
390 return {s.data(), s.length()};
391 }
392 }
393 std::string message = fmt::format(my_string("The answer is {}"), 42);
394 \endrst
395 */
396template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
398 return s;
399}
400
401template <typename Char, typename Traits, typename Alloc>
403 const std::basic_string<Char, Traits, Alloc>& s) {
404 return s;
405}
406
407template <typename Char>
411
412template <typename Char,
413 FMT_ENABLE_IF(!std::is_empty<internal::std_string_view<Char>>::value)>
418
419// A base class for compile-time strings. It is defined in the fmt namespace to
420// make formatting functions visible via ADL, e.g. format(fmt("{}"), 42).
422
423template <typename S>
424struct is_compile_string : std::is_base_of<compile_string, S> {};
425
426template <typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
428 return s;
429}
430
431namespace internal {
433using fmt::v6::to_string_view;
434
435// Specifies whether S is a string type convertible to fmt::basic_string_view.
436// It should be a constexpr function but MSVC 2017 fails to compile it in
437// enable_if and MSVC 2015 fails to compile it as an alias template.
438template <typename S>
439struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
440};
441
442template <typename S, typename = void> struct char_t_impl {};
443template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
444 using result = decltype(to_string_view(std::declval<S>()));
445 using type = typename result::char_type;
446};
447
451
452 // This function is intentionally not constexpr to give a compile-time error.
453 FMT_NORETURN FMT_API void on_error(const char* message);
454};
455} // namespace internal
456
457/** String's character type. */
458template <typename S> using char_t = typename internal::char_t_impl<S>::type;
459
460/**
461 \rst
462 Parsing context consisting of a format string range being parsed and an
463 argument counter for automatic indexing.
464
465 You can use one of the following type aliases for common character types:
466
467 +-----------------------+-------------------------------------+
468 | Type | Definition |
469 +=======================+=====================================+
470 | format_parse_context | basic_format_parse_context<char> |
471 +-----------------------+-------------------------------------+
472 | wformat_parse_context | basic_format_parse_context<wchar_t> |
473 +-----------------------+-------------------------------------+
474 \endrst
475 */
476template <typename Char, typename ErrorHandler = internal::error_handler>
477class basic_format_parse_context : private ErrorHandler {
478 private:
481
482 public:
483 using char_type = Char;
485
487 basic_string_view<Char> format_str, ErrorHandler eh = ErrorHandler())
488 : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {}
489
490 /**
491 Returns an iterator to the beginning of the format string range being
492 parsed.
493 */
495 return format_str_.begin();
496 }
497
498 /**
499 Returns an iterator past the end of the format string range being parsed.
500 */
502
503 /** Advances the begin iterator to ``it``. */
505 format_str_.remove_prefix(internal::to_unsigned(it - begin()));
506 }
507
508 /**
509 Reports an error if using the manual argument indexing; otherwise returns
510 the next argument index and switches to the automatic indexing.
511 */
513 if (next_arg_id_ >= 0) return next_arg_id_++;
514 on_error("cannot switch from manual to automatic argument indexing");
515 return 0;
516 }
517
518 /**
519 Reports an error if using the automatic argument indexing; otherwise
520 switches to the manual indexing.
521 */
523 if (next_arg_id_ > 0)
524 on_error("cannot switch from automatic to manual argument indexing");
525 else
526 next_arg_id_ = -1;
527 }
528
530
531 FMT_CONSTEXPR void on_error(const char* message) {
532 ErrorHandler::on_error(message);
533 }
534
535 FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; }
536};
537
540
541template <typename Char, typename ErrorHandler = internal::error_handler>
542using basic_parse_context FMT_DEPRECATED_ALIAS =
546
547template <typename Context> class basic_format_arg;
548template <typename Context> class basic_format_args;
549
550// A formatter for objects of type T.
551template <typename T, typename Char = char, typename Enable = void>
552struct formatter {
553 // A deleted default constructor indicates a disabled formatter.
554 formatter() = delete;
555};
556
557template <typename T, typename Char, typename Enable = void>
559 : bool_constant<!std::is_arithmetic<T>::value &&
560 std::is_convertible<T, int>::value> {};
561
562// Specifies if T has an enabled formatter specialization. A type can be
563// formattable even if it doesn't have a formatter e.g. via a conversion.
564template <typename T, typename Context>
566 std::is_constructible<typename Context::template formatter_type<T>>;
567
568namespace internal {
569
570/** A contiguous memory buffer with an optional growing ability. */
571template <typename T> class buffer {
572 private:
574 std::size_t size_;
575 std::size_t capacity_;
576
577 protected:
578 // Don't initialize ptr_ since it is not accessed to save a few cycles.
579 buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
580
581 buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
582 : ptr_(p),
583 size_(sz),
584 capacity_(cap) {}
585
586 /** Sets the buffer data and capacity. */
587 void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT {
588 ptr_ = buf_data;
589 capacity_ = buf_capacity;
590 }
591
592 /** Increases the buffer capacity to hold at least *capacity* elements. */
593 virtual void grow(std::size_t capacity) = 0;
594
595 public:
596 using value_type = T;
597 using const_reference = const T&;
598
599 buffer(const buffer&) = delete;
600 void operator=(const buffer&) = delete;
601 virtual ~buffer() = default;
602
603 T* begin() FMT_NOEXCEPT { return ptr_; }
604 T* end() FMT_NOEXCEPT { return ptr_ + size_; }
605
606 /** Returns the size of this buffer. */
607 std::size_t size() const FMT_NOEXCEPT { return size_; }
608
609 /** Returns the capacity of this buffer. */
610 std::size_t capacity() const FMT_NOEXCEPT { return capacity_; }
611
612 /** Returns a pointer to the buffer data. */
613 T* data() FMT_NOEXCEPT { return ptr_; }
614
615 /** Returns a pointer to the buffer data. */
616 const T* data() const FMT_NOEXCEPT { return ptr_; }
617
618 /**
619 Resizes the buffer. If T is a POD type new elements may not be initialized.
620 */
621 void resize(std::size_t new_size) {
622 reserve(new_size);
623 size_ = new_size;
624 }
625
626 /** Clears this buffer. */
627 void clear() { size_ = 0; }
628
629 /** Reserves space to store at least *capacity* elements. */
630 void reserve(std::size_t new_capacity) {
631 if (new_capacity > capacity_) grow(new_capacity);
632 }
633
634 void push_back(const T& value) {
635 reserve(size_ + 1);
636 ptr_[size_++] = value;
637 }
638
639 /** Appends data to the end of the buffer. */
640 template <typename U> void append(const U* begin, const U* end);
641
642 T& operator[](std::size_t index) { return ptr_[index]; }
643 const T& operator[](std::size_t index) const { return ptr_[index]; }
644};
645
646// A container-backed buffer.
647template <typename Container>
648class container_buffer : public buffer<typename Container::value_type> {
649 private:
650 Container& container_;
651
652 protected:
653 void grow(std::size_t capacity) FMT_OVERRIDE {
654 container_.resize(capacity);
655 this->set(&container_[0], capacity);
656 }
657
658 public:
659 explicit container_buffer(Container& c)
660 : buffer<typename Container::value_type>(c.size()), container_(c) {}
661};
662
663// Extracts a reference to the container from back_insert_iterator.
664template <typename Container>
665inline Container& get_container(std::back_insert_iterator<Container> it) {
666 using bi_iterator = std::back_insert_iterator<Container>;
667 struct accessor : bi_iterator {
668 accessor(bi_iterator iter) : bi_iterator(iter) {}
669 using bi_iterator::container;
670 };
671 return *accessor(it).container;
672}
673
674template <typename T, typename Char = char, typename Enable = void>
678
679// Specifies if T has an enabled fallback_formatter specialization.
680template <typename T, typename Context>
682 std::is_constructible<fallback_formatter<T, typename Context::char_type>>;
683
684template <typename Char> struct named_arg_base;
685template <typename T, typename Char> struct named_arg;
686
710
711// Maps core type T to the corresponding type enum constant.
712template <typename T, typename Char>
713struct type_constant : std::integral_constant<type, custom_type> {};
714
715#define FMT_TYPE_CONSTANT(Type, constant) \
716 template <typename Char> \
717 struct type_constant<Type, Char> : std::integral_constant<type, constant> {}
718
734
736 FMT_ASSERT(t != named_arg_type, "invalid argument type");
737 return t > none_type && t <= last_integer_type;
738}
739
741 FMT_ASSERT(t != named_arg_type, "invalid argument type");
742 return t > none_type && t <= last_numeric_type;
743}
744
745template <typename Char> struct string_value {
746 const Char* data;
747 std::size_t size;
748};
749
750template <typename Context> struct custom_value {
752 const void* value;
753 void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
754};
755
756// A formatting argument value.
757template <typename Context> class value {
758 public:
759 using char_type = typename Context::char_type;
760
761 union {
763 unsigned uint_value;
765 unsigned long long ulong_long_value;
772 long double long_double_value;
773 const void* pointer;
777 };
778
779 FMT_CONSTEXPR value(int val = 0) : int_value(val) {}
780 FMT_CONSTEXPR value(unsigned val) : uint_value(val) {}
781 value(long long val) : long_long_value(val) {}
782 value(unsigned long long val) : ulong_long_value(val) {}
785 value(float val) : float_value(val) {}
786 value(double val) : double_value(val) {}
787 value(long double val) : long_double_value(val) {}
788 value(bool val) : bool_value(val) {}
790 value(const char_type* val) { string.data = val; }
792 string.data = val.data();
793 string.size = val.size();
794 }
795 value(const void* val) : pointer(val) {}
796
797 template <typename T> value(const T& val) {
798 custom.value = &val;
799 // Get the formatter type through the context to allow different contexts
800 // have different extension points, e.g. `formatter<T>` for `format` and
801 // `printf_formatter<T>` for `printf`.
802 custom.format = format_custom_arg<
804 typename Context::template formatter_type<T>,
806 }
807
809
810 private:
811 // Formats an argument of a custom type, such as a user-defined class.
812 template <typename T, typename Formatter>
813 static void format_custom_arg(
814 const void* arg, basic_format_parse_context<char_type>& parse_ctx,
815 Context& ctx) {
816 Formatter f;
817 parse_ctx.advance_to(f.parse(parse_ctx));
818 ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
819 }
820};
821
822template <typename Context, typename T>
824
825// To minimize the number of types we need to deal with, long is translated
826// either to int or to long long depending on its size.
827enum { long_short = sizeof(long) == sizeof(int) };
830
831// Maps formatting arguments to core types.
832template <typename Context> struct arg_mapper {
833 using char_type = typename Context::char_type;
834
835 FMT_CONSTEXPR int map(signed char val) { return val; }
836 FMT_CONSTEXPR unsigned map(unsigned char val) { return val; }
837 FMT_CONSTEXPR int map(short val) { return val; }
838 FMT_CONSTEXPR unsigned map(unsigned short val) { return val; }
839 FMT_CONSTEXPR int map(int val) { return val; }
840 FMT_CONSTEXPR unsigned map(unsigned val) { return val; }
841 FMT_CONSTEXPR long_type map(long val) { return val; }
842 FMT_CONSTEXPR ulong_type map(unsigned long val) { return val; }
843 FMT_CONSTEXPR long long map(long long val) { return val; }
844 FMT_CONSTEXPR unsigned long long map(unsigned long long val) { return val; }
845 FMT_CONSTEXPR int128_t map(int128_t val) { return val; }
847 FMT_CONSTEXPR bool map(bool val) { return val; }
848
849 template <typename T, FMT_ENABLE_IF(is_char<T>::value)>
851 static_assert(
852 std::is_same<T, char>::value || std::is_same<T, char_type>::value,
853 "mixing character types is disallowed");
854 return val;
855 }
856
857 FMT_CONSTEXPR float map(float val) { return val; }
858 FMT_CONSTEXPR double map(double val) { return val; }
859 FMT_CONSTEXPR long double map(long double val) { return val; }
860
861 FMT_CONSTEXPR const char_type* map(char_type* val) { return val; }
862 FMT_CONSTEXPR const char_type* map(const char_type* val) { return val; }
863 template <typename T, FMT_ENABLE_IF(is_string<T>::value)>
865 static_assert(std::is_same<char_type, char_t<T>>::value,
866 "mixing character types is disallowed");
867 return to_string_view(val);
868 }
869 template <typename T,
871 std::is_constructible<basic_string_view<char_type>, T>::value &&
876 template <
877 typename T,
879 std::is_constructible<std_string_view<char_type>, T>::value &&
880 !std::is_constructible<basic_string_view<char_type>, T>::value &&
885 FMT_CONSTEXPR const char* map(const signed char* val) {
886 static_assert(std::is_same<char_type, char>::value, "invalid string type");
887 return reinterpret_cast<const char*>(val);
888 }
889 FMT_CONSTEXPR const char* map(const unsigned char* val) {
890 static_assert(std::is_same<char_type, char>::value, "invalid string type");
891 return reinterpret_cast<const char*>(val);
892 }
893
894 FMT_CONSTEXPR const void* map(void* val) { return val; }
895 FMT_CONSTEXPR const void* map(const void* val) { return val; }
896 FMT_CONSTEXPR const void* map(std::nullptr_t val) { return val; }
897 template <typename T> FMT_CONSTEXPR int map(const T*) {
898 // Formatting of arbitrary pointers is disallowed. If you want to output
899 // a pointer cast it to "void *" or "const void *". In particular, this
900 // forbids formatting of "[const] volatile char *" which is printed as bool
901 // by iostreams.
902 static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
903 return 0;
904 }
905
906 template <typename T,
907 FMT_ENABLE_IF(std::is_enum<T>::value &&
910 FMT_CONSTEXPR auto map(const T& val) -> decltype(
911 map(static_cast<typename std::underlying_type<T>::type>(val))) {
912 return map(static_cast<typename std::underlying_type<T>::type>(val));
913 }
914 template <
915 typename T,
918 !std::is_constructible<basic_string_view<char_type>, T>::value &&
921 !std::is_constructible<std_string_view<char_type>, T>::value)))>
922 FMT_CONSTEXPR const T& map(const T& val) {
923 return val;
924 }
925
926 template <typename T>
928 const named_arg<T, char_type>& val) {
929 auto arg = make_arg<Context>(val.value);
930 std::memcpy(val.data, &arg, sizeof(arg));
931 return val;
932 }
933};
934
935// A type constant after applying arg_mapper<Context>.
936template <typename T, typename Context>
938 type_constant<decltype(arg_mapper<Context>().map(std::declval<const T&>())),
939 typename Context::char_type>;
940
941enum { packed_arg_bits = 5 };
942// Maximum number of arguments with packed types.
944enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
945
946template <typename Context> class arg_map;
947} // namespace internal
948
949// A formatting argument. It is a trivially copyable/constructible type to
950// allow storage in basic_memory_buffer.
951template <typename Context> class basic_format_arg {
952 private:
955
956 template <typename ContextType, typename T>
958 const T& value);
959
960 template <typename Visitor, typename Ctx>
961 friend FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
963 -> decltype(vis(0));
964
965 friend class basic_format_args<Context>;
966 friend class internal::arg_map<Context>;
967
968 using char_type = typename Context::char_type;
969
970 public:
971 class handle {
972 public:
973 explicit handle(internal::custom_value<Context> custom) : custom_(custom) {}
974
976 Context& ctx) const {
977 custom_.format(custom_.value, parse_ctx, ctx);
978 }
979
980 private:
982 };
983
985
986 FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT {
987 return type_ != internal::none_type;
988 }
989
990 internal::type type() const { return type_; }
991
994};
995
996/**
997 \rst
998 Visits an argument dispatching to the appropriate visit method based on
999 the argument type. For example, if the argument type is ``double`` then
1000 ``vis(value)`` will be called with the value of type ``double``.
1001 \endrst
1002 */
1003template <typename Visitor, typename Context>
1006 -> decltype(vis(0)) {
1007 using char_type = typename Context::char_type;
1008 switch (arg.type_) {
1010 break;
1012 FMT_ASSERT(false, "invalid argument type");
1013 break;
1014 case internal::int_type:
1015 return vis(arg.value_.int_value);
1017 return vis(arg.value_.uint_value);
1019 return vis(arg.value_.long_long_value);
1021 return vis(arg.value_.ulong_long_value);
1022#if FMT_USE_INT128
1024 return vis(arg.value_.int128_value);
1026 return vis(arg.value_.uint128_value);
1027#else
1030 break;
1031#endif
1033 return vis(arg.value_.bool_value);
1035 return vis(arg.value_.char_value);
1037 return vis(arg.value_.float_value);
1039 return vis(arg.value_.double_value);
1041 return vis(arg.value_.long_double_value);
1043 return vis(arg.value_.string.data);
1045 return vis(basic_string_view<char_type>(arg.value_.string.data,
1046 arg.value_.string.size));
1048 return vis(arg.value_.pointer);
1050 return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
1051 }
1052 return vis(monostate());
1053}
1054
1055namespace internal {
1056// A map from argument names to their values for named arguments.
1057template <typename Context> class arg_map {
1058 private:
1059 using char_type = typename Context::char_type;
1060
1065
1067 unsigned size_;
1068
1070 const auto& named = *val.named_arg;
1071 map_[size_] = {named.name, named.template deserialize<Context>()};
1072 ++size_;
1073 }
1074
1075 public:
1076 arg_map(const arg_map&) = delete;
1077 void operator=(const arg_map&) = delete;
1078 arg_map() : map_(nullptr), size_(0) {}
1079 void init(const basic_format_args<Context>& args);
1080 ~arg_map() { delete[] map_; }
1081
1083 // The list is unsorted, so just return the first matching name.
1084 for (entry *it = map_, *end = map_ + size_; it != end; ++it) {
1085 if (it->name == name) return it->arg;
1086 }
1087 return {};
1088 }
1089};
1090
1091// A type-erased reference to an std::locale to avoid heavy <locale> include.
1093 private:
1094 const void* locale_; // A type-erased pointer to std::locale.
1095
1096 public:
1097 locale_ref() : locale_(nullptr) {}
1098 template <typename Locale> explicit locale_ref(const Locale& loc);
1099
1100 explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; }
1101
1102 template <typename Locale> Locale get() const;
1103};
1104
1105template <typename> constexpr unsigned long long encode_types() { return 0; }
1106
1107template <typename Context, typename Arg, typename... Args>
1108constexpr unsigned long long encode_types() {
1110 (encode_types<Context, Args...>() << packed_arg_bits);
1111}
1112
1113template <typename Context, typename T>
1120
1121template <bool IS_PACKED, typename Context, typename T,
1122 FMT_ENABLE_IF(IS_PACKED)>
1123inline value<Context> make_arg(const T& val) {
1124 return arg_mapper<Context>().map(val);
1125}
1126
1127template <bool IS_PACKED, typename Context, typename T,
1128 FMT_ENABLE_IF(!IS_PACKED)>
1130 return make_arg<Context>(value);
1131}
1132} // namespace internal
1133
1134// Formatting context.
1135template <typename OutputIt, typename Char> class basic_format_context {
1136 public:
1137 /** The character type for the output. */
1138 using char_type = Char;
1139
1140 private:
1141 OutputIt out_;
1145
1146 public:
1147 using iterator = OutputIt;
1149 template <typename T> using formatter_type = formatter<T, char_type>;
1150
1152 void operator=(const basic_format_context&) = delete;
1153 /**
1154 Constructs a ``basic_format_context`` object. References to the arguments are
1155 stored in the object so make sure they have appropriate lifetimes.
1156 */
1161
1162 format_arg arg(int id) const { return args_.get(id); }
1163
1164 // Checks if manual indexing is used and returns the argument with the
1165 // specified name.
1167
1169 void on_error(const char* message) { error_handler().on_error(message); }
1170
1171 // Returns an iterator to the beginning of the output range.
1172 iterator out() { return out_; }
1173
1174 // Advances the begin iterator to ``it``.
1175 void advance_to(iterator it) { out_ = it; }
1176
1178};
1179
1180template <typename Char>
1183 Char>;
1186
1187/**
1188 \rst
1189 An array of references to arguments. It can be implicitly converted into
1190 `~fmt::basic_format_args` for passing into type-erased formatting functions
1191 such as `~fmt::vformat`.
1192 \endrst
1193 */
1194template <typename Context, typename... Args> class format_arg_store {
1195 private:
1196 static const size_t num_args = sizeof...(Args);
1198
1201
1202 // If the arguments are not packed, add one more element to mark the end.
1204
1205 friend class basic_format_args<Context>;
1206
1207 public:
1208 static constexpr unsigned long long types =
1209 is_packed ? internal::encode_types<Context, Args...>()
1210 : internal::is_unpacked_bit | num_args;
1211
1212 format_arg_store(const Args&... args)
1213 : data_{internal::make_arg<is_packed, Context>(args)...} {}
1214};
1215
1216/**
1217 \rst
1218 Constructs an `~fmt::format_arg_store` object that contains references to
1219 arguments and can be implicitly converted to `~fmt::format_args`. `Context`
1220 can be omitted in which case it defaults to `~fmt::context`.
1221 See `~fmt::arg` for lifetime considerations.
1222 \endrst
1223 */
1224template <typename Context = format_context, typename... Args>
1225inline format_arg_store<Context, Args...> make_format_args(
1226 const Args&... args) {
1227 return {args...};
1228}
1229
1230/** Formatting arguments. */
1231template <typename Context> class basic_format_args {
1232 public:
1233 using size_type = int;
1235
1236 private:
1237 // To reduce compiled code size per formatting function call, types of first
1238 // max_packed_args arguments are passed in the types_ field.
1239 unsigned long long types_;
1240 union {
1241 // If the number of arguments is less than max_packed_args, the argument
1242 // values are stored in values_, otherwise they are stored in args_.
1243 // This is done to reduce compiled code size as storing larger objects
1244 // may require more code (at least on x86-64) even if the same amount of
1245 // data is actually copied to stack. It saves ~10% on the bloat test.
1248 };
1249
1250 bool is_packed() const { return (types_ & internal::is_unpacked_bit) == 0; }
1251
1252 internal::type type(int index) const {
1253 int shift = index * internal::packed_arg_bits;
1254 unsigned int mask = (1 << internal::packed_arg_bits) - 1;
1255 return static_cast<internal::type>((types_ >> shift) & mask);
1256 }
1257
1258 friend class internal::arg_map<Context>;
1259
1260 void set_data(const internal::value<Context>* values) { values_ = values; }
1261 void set_data(const format_arg* args) { args_ = args; }
1262
1263 format_arg do_get(int index) const {
1265 if (!is_packed()) {
1266 auto num_args = max_size();
1267 if (index < num_args) arg = args_[index];
1268 return arg;
1269 }
1270 if (index > internal::max_packed_args) return arg;
1271 arg.type_ = type(index);
1272 if (arg.type_ == internal::none_type) return arg;
1273 internal::value<Context>& val = arg.value_;
1274 val = values_[index];
1275 return arg;
1276 }
1277
1278 public:
1280
1281 /**
1282 \rst
1283 Constructs a `basic_format_args` object from `~fmt::format_arg_store`.
1284 \endrst
1285 */
1286 template <typename... Args>
1288 : types_(store.types) {
1289 set_data(store.data_);
1290 }
1291
1292 /**
1293 \rst
1294 Constructs a `basic_format_args` object from a dynamic set of arguments.
1295 \endrst
1296 */
1297 basic_format_args(const format_arg* args, int count)
1298 : types_(internal::is_unpacked_bit | internal::to_unsigned(count)) {
1299 set_data(args);
1300 }
1301
1302 /** Returns the argument at specified index. */
1303 format_arg get(int index) const {
1304 format_arg arg = do_get(index);
1305 if (arg.type_ == internal::named_arg_type)
1306 arg = arg.value_.named_arg->template deserialize<Context>();
1307 return arg;
1308 }
1309
1310 int max_size() const {
1311 unsigned long long max_packed = internal::max_packed_args;
1312 return static_cast<int>(is_packed() ? max_packed
1313 : types_ & ~internal::is_unpacked_bit);
1314 }
1315};
1316
1317/** An alias to ``basic_format_args<context>``. */
1318// It is a separate type rather than an alias to make symbols readable.
1319struct format_args : basic_format_args<format_context> {
1320 template <typename... Args>
1321 format_args(Args&&... args)
1322 : basic_format_args<format_context>(std::forward<Args>(args)...) {}
1323};
1324struct wformat_args : basic_format_args<wformat_context> {
1325 template <typename... Args>
1326 wformat_args(Args&&... args)
1327 : basic_format_args<wformat_context>(std::forward<Args>(args)...) {}
1328};
1329
1330template <typename Container> struct is_contiguous : std::false_type {};
1331
1332template <typename Char>
1333struct is_contiguous<std::basic_string<Char>> : std::true_type {};
1334
1335template <typename Char>
1336struct is_contiguous<internal::buffer<Char>> : std::true_type {};
1337
1338namespace internal {
1339
1340template <typename OutputIt>
1341struct is_contiguous_back_insert_iterator : std::false_type {};
1342template <typename Container>
1343struct is_contiguous_back_insert_iterator<std::back_insert_iterator<Container>>
1344 : is_contiguous<Container> {};
1345
1346template <typename Char> struct named_arg_base {
1348
1349 // Serialized value<context>.
1351
1353
1354 template <typename Context> basic_format_arg<Context> deserialize() const {
1356 std::memcpy(&arg, data, sizeof(basic_format_arg<Context>));
1357 return arg;
1358 }
1359};
1360
1361template <typename T, typename Char> struct named_arg : named_arg_base<Char> {
1362 const T& value;
1363
1365 : named_arg_base<Char>(name), value(val) {}
1366};
1367
1368template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
1369inline void check_format_string(const S&) {
1370#if defined(FMT_ENFORCE_COMPILE_STRING)
1371 static_assert(is_compile_string<S>::value,
1372 "FMT_ENFORCE_COMPILE_STRING requires all format strings to "
1373 "utilize FMT_STRING() or fmt().");
1374#endif
1375}
1376template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
1377void check_format_string(S);
1378
1379struct view {};
1380template <bool...> struct bool_pack;
1381template <bool... Args>
1383 std::is_same<bool_pack<Args..., true>, bool_pack<true, Args...>>;
1384
1385template <typename... Args, typename S, typename Char = char_t<S>>
1387make_args_checked(const S& format_str,
1388 const remove_reference_t<Args>&... args) {
1389 static_assert(all_true<(!std::is_base_of<view, remove_reference_t<Args>>() ||
1390 !std::is_reference<Args>())...>::value,
1391 "passing views as lvalues is disallowed");
1392 check_format_string<remove_const_t<remove_reference_t<Args>>...>(format_str);
1393 return {args...};
1394}
1395
1396template <typename Char>
1397std::basic_string<Char> vformat(basic_string_view<Char> format_str,
1399
1400template <typename Char>
1402 buffer<Char>& buf, basic_string_view<Char> format_str,
1404} // namespace internal
1405
1406/**
1407 \rst
1408 Returns a named argument to be used in a formatting function.
1409
1410 The named argument holds a reference and does not extend the lifetime
1411 of its arguments.
1412 Consequently, a dangling reference can accidentally be created.
1413 The user should take care to only pass this function temporaries when
1414 the named argument is itself a temporary, as per the following example.
1415
1416 **Example**::
1417
1418 fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23));
1419 \endrst
1420 */
1421template <typename S, typename T, typename Char = char_t<S>>
1422inline internal::named_arg<T, Char> arg(const S& name, const T& arg) {
1423 static_assert(internal::is_string<S>::value, "");
1424 return {name, arg};
1425}
1426
1427// Disable nested named arguments, e.g. ``arg("a", arg("b", 42))``.
1428template <typename S, typename T, typename Char>
1430
1431/** Formats a string and writes the output to ``out``. */
1432// GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
1433// vformat_to<ArgFormatter>(...) overload, so SFINAE on iterator type instead.
1434template <typename OutputIt, typename S, typename Char = char_t<S>,
1435 FMT_ENABLE_IF(
1436 internal::is_contiguous_back_insert_iterator<OutputIt>::value)>
1437OutputIt vformat_to(OutputIt out, const S& format_str,
1439 using container = remove_reference_t<decltype(internal::get_container(out))>;
1441 internal::vformat_to(buf, to_string_view(format_str), args);
1442 return out;
1443}
1444
1445template <typename Container, typename S, typename... Args,
1448inline std::back_insert_iterator<Container> format_to(
1449 std::back_insert_iterator<Container> out, const S& format_str,
1450 Args&&... args) {
1451 return vformat_to(
1452 out, to_string_view(format_str),
1453 {internal::make_args_checked<Args...>(format_str, args...)});
1454}
1455
1456template <typename S, typename Char = char_t<S>>
1457inline std::basic_string<Char> vformat(
1458 const S& format_str, basic_format_args<buffer_context<Char>> args) {
1459 return internal::vformat(to_string_view(format_str), args);
1460}
1461
1462/**
1463 \rst
1464 Formats arguments and returns the result as a string.
1465
1466 **Example**::
1467
1468 #include <fmt/core.h>
1469 std::string message = fmt::format("The answer is {}", 42);
1470 \endrst
1471*/
1472// Pass char_t as a default template parameter instead of using
1473// std::basic_string<char_t<S>> to reduce the symbol size.
1474template <typename S, typename... Args, typename Char = char_t<S>>
1475inline std::basic_string<Char> format(const S& format_str, Args&&... args) {
1476 return internal::vformat(
1477 to_string_view(format_str),
1478 {internal::make_args_checked<Args...>(format_str, args...)});
1479}
1480
1481FMT_API void vprint(std::FILE* f, string_view format_str, format_args args);
1482FMT_API void vprint(string_view format_str, format_args args);
1483
1484/**
1485 \rst
1486 Prints formatted data to the file *f*. For wide format strings,
1487 *f* should be in wide-oriented mode set via ``fwide(f, 1)`` or
1488 ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows.
1489
1490 **Example**::
1491
1492 fmt::print(stderr, "Don't {}!", "panic");
1493 \endrst
1494 */
1495template <typename S, typename... Args,
1497inline void print(std::FILE* f, const S& format_str, Args&&... args) {
1498 vprint(f, to_string_view(format_str),
1499 internal::make_args_checked<Args...>(format_str, args...));
1500}
1501
1502/**
1503 \rst
1504 Prints formatted data to ``stdout``.
1505
1506 **Example**::
1507
1508 fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
1509 \endrst
1510 */
1511template <typename S, typename... Args,
1513inline void print(const S& format_str, Args&&... args) {
1514 vprint(to_string_view(format_str),
1515 internal::make_args_checked<Args...>(format_str, args...));
1516}
1518
1519#endif // FMT_CORE_H_
void format(basic_format_parse_context< char_type > &parse_ctx, Context &ctx) const
Definition core.h:975
handle(internal::custom_value< Context > custom)
Definition core.h:973
internal::custom_value< Context > custom_
Definition core.h:981
internal::value< Context > value_
Definition core.h:953
bool is_integral() const
Definition core.h:992
internal::type type() const
Definition core.h:990
FMT_CONSTEXPR basic_format_arg()
Definition core.h:984
internal::type type_
Definition core.h:954
friend FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Ctx > &arg) -> decltype(vis(0))
typename Context::char_type char_type
Definition core.h:968
bool is_arithmetic() const
Definition core.h:993
const internal::value< Context > * values_
Definition core.h:1246
basic_format_args(const format_arg *args, int count)
Definition core.h:1297
format_arg get(int index) const
Definition core.h:1303
basic_format_args(const format_arg_store< Context, Args... > &store)
Definition core.h:1287
void set_data(const internal::value< Context > *values)
Definition core.h:1260
void set_data(const format_arg *args)
Definition core.h:1261
format_arg do_get(int index) const
Definition core.h:1263
const format_arg * args_
Definition core.h:1247
unsigned long long types_
Definition core.h:1239
bool is_packed() const
Definition core.h:1250
internal::type type(int index) const
Definition core.h:1252
int max_size() const
Definition core.h:1310
format_arg arg(int id) const
Definition core.h:1162
void advance_to(iterator it)
Definition core.h:1175
basic_format_context(OutputIt out, basic_format_args< basic_format_context > ctx_args, internal::locale_ref loc=internal::locale_ref())
Definition core.h:1157
internal::locale_ref locale()
Definition core.h:1177
iterator out()
Definition core.h:1172
void on_error(const char *message)
Definition core.h:1169
internal::arg_map< basic_format_context > map_
Definition core.h:1143
void operator=(const basic_format_context &)=delete
basic_format_args< basic_format_context > args_
Definition core.h:1142
OutputIt iterator
Definition core.h:1147
basic_format_arg< basic_format_context > format_arg
Definition core.h:1148
internal::error_handler error_handler()
Definition core.h:1168
basic_format_context(const basic_format_context &)=delete
internal::locale_ref loc_
Definition core.h:1144
FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT
Definition core.h:494
FMT_CONSTEXPR void advance_to(iterator it)
Definition core.h:504
FMT_CONSTEXPR void on_error(const char *message)
Definition core.h:531
FMT_CONSTEXPR void check_arg_id(int)
Definition core.h:522
FMT_CONSTEXPR void check_arg_id(basic_string_view< Char >)
Definition core.h:529
FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT
Definition core.h:501
typename basic_string_view< Char >::iterator iterator
Definition core.h:484
basic_string_view< Char > format_str_
Definition core.h:479
FMT_CONSTEXPR ErrorHandler error_handler() const
Definition core.h:535
FMT_CONSTEXPR int next_arg_id()
Definition core.h:512
FMT_CONSTEXPR basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh=ErrorHandler())
Definition core.h:486
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT
Definition core.h:290
friend bool operator<(basic_string_view lhs, basic_string_view rhs)
Definition core.h:350
friend bool operator>=(basic_string_view lhs, basic_string_view rhs)
Definition core.h:359
FMT_CONSTEXPR void remove_prefix(size_t n)
Definition core.h:330
int compare(basic_string_view other) const
Definition core.h:336
FMT_CONSTEXPR size_t size() const
Definition core.h:323
friend bool operator!=(basic_string_view lhs, basic_string_view rhs)
Definition core.h:347
size_t size_
Definition core.h:284
const Char * iterator
Definition core.h:288
FMT_CONSTEXPR iterator end() const
Definition core.h:326
friend bool operator>(basic_string_view lhs, basic_string_view rhs)
Definition core.h:356
FMT_CONSTEXPR const Char * data() const
Definition core.h:320
friend bool operator<=(basic_string_view lhs, basic_string_view rhs)
Definition core.h:353
FMT_CONSTEXPR basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
Definition core.h:293
FMT_CONSTEXPR iterator begin() const
Definition core.h:325
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Traits, Alloc > &s) FMT_NOEXCEPT
Definition core.h:308
friend bool operator==(basic_string_view lhs, basic_string_view rhs)
Definition core.h:344
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT
Definition core.h:316
basic_string_view(const Char *s)
Definition core.h:303
FMT_CONSTEXPR const Char & operator[](size_t pos) const
Definition core.h:328
const Char * data_
Definition core.h:283
static const size_t num_args
Definition core.h:1196
static const bool is_packed
Definition core.h:1197
conditional_t< is_packed, internal::value< Context >, basic_format_arg< Context > > value_type
Definition core.h:1199
value_type data_[num_args+(num_args==0 ? 1 :0)]
Definition core.h:1203
format_arg_store(const Args &... args)
Definition core.h:1212
static constexpr unsigned long long types
Definition core.h:1208
entry * map_
Definition core.h:1066
void init(const basic_format_args< Context > &args)
Definition format.h:1345
basic_format_arg< Context > find(basic_string_view< char_type > name) const
Definition core.h:1082
arg_map(const arg_map &)=delete
void operator=(const arg_map &)=delete
unsigned size_
Definition core.h:1067
typename Context::char_type char_type
Definition core.h:1059
void push_back(value< Context > val)
Definition core.h:1069
void reserve(std::size_t new_capacity)
Definition core.h:630
const T & operator[](std::size_t index) const
Definition core.h:643
buffer(T *p=nullptr, std::size_t sz=0, std::size_t cap=0) FMT_NOEXCEPT
Definition core.h:581
T * begin() FMT_NOEXCEPT
Definition core.h:603
T * data() FMT_NOEXCEPT
Definition core.h:613
void append(const U *begin, const U *end)
Definition format.h:527
buffer(const buffer &)=delete
buffer(std::size_t sz) FMT_NOEXCEPT
Definition core.h:579
void operator=(const buffer &)=delete
std::size_t capacity_
Definition core.h:575
void push_back(const T &value)
Definition core.h:634
virtual void grow(std::size_t capacity)=0
void resize(std::size_t new_size)
Definition core.h:621
virtual ~buffer()=default
std::size_t size() const FMT_NOEXCEPT
Definition core.h:607
const T * data() const FMT_NOEXCEPT
Definition core.h:616
void set(T *buf_data, std::size_t buf_capacity) FMT_NOEXCEPT
Definition core.h:587
void clear()
Definition core.h:627
const T & const_reference
Definition core.h:597
T * end() FMT_NOEXCEPT
Definition core.h:604
T & operator[](std::size_t index)
Definition core.h:642
std::size_t size_
Definition core.h:574
std::size_t capacity() const FMT_NOEXCEPT
Definition core.h:610
Container & container_
Definition core.h:650
container_buffer(Container &c)
Definition core.h:659
void grow(std::size_t capacity) FMT_OVERRIDE
Definition core.h:653
Locale get() const
Definition format-inl.h:198
const void * locale_
Definition core.h:1094
int int_value
Definition core.h:762
static void format_custom_arg(const void *arg, basic_format_parse_context< char_type > &parse_ctx, Context &ctx)
Definition core.h:813
value(double val)
Definition core.h:786
uint128_t uint128_value
Definition core.h:767
value(int128_t val)
Definition core.h:783
const named_arg_base< char_type > * named_arg
Definition core.h:776
value(const T &val)
Definition core.h:797
unsigned uint_value
Definition core.h:763
int128_t int128_value
Definition core.h:766
value(long double val)
Definition core.h:787
custom_value< Context > custom
Definition core.h:775
value(bool val)
Definition core.h:788
char_type char_value
Definition core.h:769
double double_value
Definition core.h:771
FMT_CONSTEXPR value(int val=0)
Definition core.h:779
value(const char_type *val)
Definition core.h:790
value(uint128_t val)
Definition core.h:784
value(unsigned long long val)
Definition core.h:782
long long long_long_value
Definition core.h:764
bool bool_value
Definition core.h:768
value(const void *val)
Definition core.h:795
value(basic_string_view< char_type > val)
Definition core.h:791
value(float val)
Definition core.h:785
const void * pointer
Definition core.h:773
FMT_CONSTEXPR value(unsigned val)
Definition core.h:780
typename Context::char_type char_type
Definition core.h:759
value(char_type val)
Definition core.h:789
string_value< char_type > string
Definition core.h:774
long double long_double_value
Definition core.h:772
value(const named_arg_base< char_type > &val)
Definition core.h:808
unsigned long long ulong_long_value
Definition core.h:765
value(long long val)
Definition core.h:781
float float_value
Definition core.h:770
typename std::enable_if< B, T >::type enable_if_t
Definition core.h:204
#define FMT_OVERRIDE
Definition core.h:84
#define FMT_ASSERT(condition, message)
Definition core.h:233
std::integral_constant< bool, B > bool_constant
Definition core.h:207
#define FMT_TYPE_CONSTANT(Type, constant)
Definition core.h:715
std::back_insert_iterator< Container > format_to(std::back_insert_iterator< Container > out, const S &format_str, Args &&... args)
Definition core.h:1448
internal::named_arg< T, Char > arg(const S &name, const T &arg)
Definition core.h:1422
typename std::remove_const< T >::type remove_const_t
Definition core.h:211
typename std::remove_reference< T >::type remove_reference_t
Definition core.h:209
buffer_context< char > format_context
Definition core.h:1184
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition core.h:213
OutputIt vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< Char > > args)
Definition core.h:1437
#define FMT_CONSTEXPR
Definition core.h:75
FMT_API void vprint(std::FILE *f, string_view format_str, format_args args)
format_arg_store< Context, Args... > make_format_args(const Args &... args)
Definition core.h:1225
#define FMT_BEGIN_NAMESPACE
Definition core.h:163
#define FMT_DEPRECATED
Definition core.h:137
FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition core.h:1004
std::is_constructible< typename Context::template formatter_type< T > > has_formatter
Definition core.h:565
#define FMT_API
Definition core.h:177
basic_string_view< Char > to_string_view(const Char *s)
Definition core.h:397
#define FMT_ENABLE_IF(...)
Definition core.h:220
typename internal::char_t_impl< S >::type char_t
Definition core.h:458
#define FMT_NORETURN
Definition core.h:124
void print(std::FILE *f, const S &format_str, Args &&... args)
Definition core.h:1497
typename std::conditional< B, T, F >::type conditional_t
Definition core.h:206
std::basic_string< Char > vformat(const S &format_str, basic_format_args< buffer_context< Char > > args)
Definition core.h:1457
char8_t
Definition core.h:369
std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition core.h:1475
#define FMT_END_NAMESPACE
Definition core.h:158
#define FMT_NOEXCEPT
Definition core.h:116
typename internal::void_t_impl< Ts... >::type void_t
Definition core.h:272
constexpr unsigned long long encode_types()
Definition core.h:1105
void vformat_to(basic_memory_buffer< Char > &buf, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< Char > > args)
Definition color.h:473
Container & get_container(std::back_insert_iterator< Container > it)
Definition core.h:665
void to_string_view(...)
conditional_t< long_short, unsigned, unsigned long long > ulong_type
Definition core.h:829
FMT_CONSTEXPR bool is_arithmetic_type(type t)
Definition core.h:740
FMT_API void assert_fail(const char *file, int line, const char *message)
Definition format-inl.h:58
FMT_CONSTEXPR basic_format_arg< Context > make_arg(const T &value)
Definition core.h:1114
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition core.h:265
format_arg_store< buffer_context< Char >, remove_reference_t< Args >... > make_args_checked(const S &format_str, const remove_reference_t< Args > &... args)
Definition core.h:1387
@ packed_arg_bits
Definition core.h:941
std::is_constructible< fallback_formatter< T, typename Context::char_type > > has_fallback_formatter
Definition core.h:681
@ named_arg_type
Definition core.h:689
@ last_numeric_type
Definition core.h:704
@ int_type
Definition core.h:691
@ ulong_long_type
Definition core.h:694
@ uint128_type
Definition core.h:696
@ none_type
Definition core.h:688
@ pointer_type
Definition core.h:707
@ float_type
Definition core.h:701
@ cstring_type
Definition core.h:705
@ custom_type
Definition core.h:708
@ uint_type
Definition core.h:692
@ long_long_type
Definition core.h:693
@ last_integer_type
Definition core.h:699
@ bool_type
Definition core.h:697
@ int128_type
Definition core.h:695
@ double_type
Definition core.h:702
@ long_double_type
Definition core.h:703
@ char_type
Definition core.h:698
@ string_type
Definition core.h:706
std::is_same< bool_pack< Args..., true >, bool_pack< true, Args... > > all_true
Definition core.h:1382
void check_format_string(const S &)
Definition core.h:1369
@ long_short
Definition core.h:827
conditional_t< long_short, int, long long > long_type
Definition core.h:828
FMT_CONSTEXPR bool is_integral_type(type t)
Definition core.h:735
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< buffer_context< Char > > args)
Definition format.h:3379
@ is_unpacked_bit
Definition core.h:944
@ max_packed_args
Definition core.h:943
format_args(Args &&... args)
Definition core.h:1321
formatter()=delete
basic_format_arg< Context > arg
Definition core.h:1063
basic_string_view< char_type > name
Definition core.h:1062
FMT_CONSTEXPR basic_string_view< char_type > map(const T &val)
Definition core.h:864
FMT_CONSTEXPR int map(int val)
Definition core.h:839
FMT_CONSTEXPR unsigned map(unsigned val)
Definition core.h:840
FMT_CONSTEXPR const char_type * map(char_type *val)
Definition core.h:861
FMT_CONSTEXPR const char * map(const unsigned char *val)
Definition core.h:889
FMT_CONSTEXPR ulong_type map(unsigned long val)
Definition core.h:842
FMT_CONSTEXPR long_type map(long val)
Definition core.h:841
FMT_CONSTEXPR const char * map(const signed char *val)
Definition core.h:885
FMT_CONSTEXPR const void * map(const void *val)
Definition core.h:895
FMT_CONSTEXPR unsigned long long map(unsigned long long val)
Definition core.h:844
FMT_CONSTEXPR int128_t map(int128_t val)
Definition core.h:845
FMT_CONSTEXPR const named_arg_base< char_type > & map(const named_arg< T, char_type > &val)
Definition core.h:927
FMT_CONSTEXPR int map(signed char val)
Definition core.h:835
FMT_CONSTEXPR float map(float val)
Definition core.h:857
FMT_CONSTEXPR uint128_t map(uint128_t val)
Definition core.h:846
FMT_CONSTEXPR char_type map(T val)
Definition core.h:850
FMT_CONSTEXPR bool map(bool val)
Definition core.h:847
FMT_CONSTEXPR double map(double val)
Definition core.h:858
FMT_CONSTEXPR const void * map(std::nullptr_t val)
Definition core.h:896
FMT_CONSTEXPR int map(const T *)
Definition core.h:897
FMT_CONSTEXPR const T & map(const T &val)
Definition core.h:922
FMT_CONSTEXPR auto map(const T &val) -> decltype(map(static_cast< typename std::underlying_type< T >::type >(val)))
Definition core.h:910
typename Context::char_type char_type
Definition core.h:833
FMT_CONSTEXPR const void * map(void *val)
Definition core.h:894
FMT_CONSTEXPR const char_type * map(const char_type *val)
Definition core.h:862
FMT_CONSTEXPR long double map(long double val)
Definition core.h:859
FMT_CONSTEXPR unsigned map(unsigned char val)
Definition core.h:836
FMT_CONSTEXPR unsigned map(unsigned short val)
Definition core.h:838
FMT_CONSTEXPR int map(short val)
Definition core.h:837
FMT_CONSTEXPR long long map(long long val)
Definition core.h:843
decltype(to_string_view(std::declval< S >())) result
Definition core.h:444
void(* format)(const void *arg, parse_context &parse_ctx, Context &ctx)
Definition core.h:753
const void * value
Definition core.h:752
FMT_CONSTEXPR error_handler(const error_handler &)=default
FMT_CONSTEXPR error_handler()=default
FMT_NORETURN FMT_API void on_error(const char *message)
named_arg_base(basic_string_view< Char > nm)
Definition core.h:1352
basic_format_arg< Context > deserialize() const
Definition core.h:1354
basic_string_view< Char > name
Definition core.h:1347
char data[sizeof(basic_format_arg< buffer_context< Char > >)]
Definition core.h:1350
const T & value
Definition core.h:1362
named_arg(basic_string_view< Char > name, const T &val)
Definition core.h:1364
std::size_t size
Definition core.h:747
const Char * data
Definition core.h:746
wformat_args(Args &&... args)
Definition core.h:1326