HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <cassert>
12 #include <cstdio> // std::FILE
13 #include <cstring>
14 #include <iterator>
15 #include <string>
16 #include <type_traits>
17 
18 // The fmt library version in the form major * 10000 + minor * 100 + patch.
19 #define FMT_VERSION 50202
20 
21 #ifdef __has_feature
22 # define FMT_HAS_FEATURE(x) __has_feature(x)
23 #else
24 # define FMT_HAS_FEATURE(x) 0
25 #endif
26 
27 #if defined(__has_include) && !defined(__INTELLISENSE__) && \
28  !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600)
29 # define FMT_HAS_INCLUDE(x) __has_include(x)
30 #else
31 # define FMT_HAS_INCLUDE(x) 0
32 #endif
33 
34 #ifdef __has_cpp_attribute
35 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
36 #else
37 # define FMT_HAS_CPP_ATTRIBUTE(x) 0
38 #endif
39 
40 #if defined(__GNUC__) && !defined(__clang__)
41 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
42 #else
43 # define FMT_GCC_VERSION 0
44 #endif
45 
46 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
47 # define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION
48 #else
49 # define FMT_HAS_GXX_CXX11 0
50 #endif
51 
52 #ifdef _MSC_VER
53 # define FMT_MSC_VER _MSC_VER
54 #else
55 # define FMT_MSC_VER 0
56 #endif
57 
58 // Check if relaxed C++14 constexpr is supported.
59 // GCC doesn't allow throw in constexpr until version 6 (bug 67371).
60 #ifndef FMT_USE_CONSTEXPR
61 # define FMT_USE_CONSTEXPR \
62  (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \
63  (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L))
64 #endif
65 #if FMT_USE_CONSTEXPR
66 # define FMT_CONSTEXPR constexpr
67 # define FMT_CONSTEXPR_DECL constexpr
68 #else
69 # define FMT_CONSTEXPR inline
70 # define FMT_CONSTEXPR_DECL
71 #endif
72 
73 #ifndef FMT_USE_CONSTEXPR11
74 # define FMT_USE_CONSTEXPR11 \
75  (FMT_USE_CONSTEXPR || FMT_GCC_VERSION >= 406 || FMT_MSC_VER >= 1900)
76 #endif
77 #if FMT_USE_CONSTEXPR11
78 # define FMT_CONSTEXPR11 constexpr
79 #else
80 # define FMT_CONSTEXPR11
81 #endif
82 
83 #ifndef FMT_OVERRIDE
84 # if FMT_HAS_FEATURE(cxx_override) || \
85  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
86 # define FMT_OVERRIDE override
87 # else
88 # define FMT_OVERRIDE
89 # endif
90 #endif
91 
92 #if FMT_HAS_FEATURE(cxx_explicit_conversions) || \
93  FMT_GCC_VERSION >= 405 || FMT_MSC_VER >= 1800
94 # define FMT_USE_EXPLICIT 1
95 # define FMT_EXPLICIT explicit
96 #else
97 # define FMT_USE_EXPLICIT 0
98 # define FMT_EXPLICIT
99 #endif
100 
101 #ifndef FMT_NULL
102 # if FMT_HAS_FEATURE(cxx_nullptr) || \
103  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600
104 # define FMT_NULL nullptr
105 # define FMT_USE_NULLPTR 1
106 # else
107 # define FMT_NULL NULL
108 # endif
109 #endif
110 #ifndef FMT_USE_NULLPTR
111 # define FMT_USE_NULLPTR 0
112 #endif
113 
114 // Check if exceptions are disabled.
115 #if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
116  FMT_MSC_VER && !_HAS_EXCEPTIONS
117 # define FMT_EXCEPTIONS 0
118 #else
119 # define FMT_EXCEPTIONS 1
120 #endif
121 
122 // Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature).
123 #ifndef FMT_USE_NOEXCEPT
124 # define FMT_USE_NOEXCEPT 0
125 #endif
126 
127 #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
128  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
129 # define FMT_DETECTED_NOEXCEPT noexcept
130 # define FMT_HAS_CXX11_NOEXCEPT 1
131 #else
132 # define FMT_DETECTED_NOEXCEPT throw()
133 # define FMT_HAS_CXX11_NOEXCEPT 0
134 #endif
135 
136 #ifndef FMT_NOEXCEPT
137 # if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT
138 # define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT
139 # else
140 # define FMT_NOEXCEPT
141 # endif
142 #endif
143 
144 #ifndef FMT_BEGIN_NAMESPACE
145 # if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \
146  FMT_MSC_VER >= 1900
147 # define FMT_INLINE_NAMESPACE inline namespace
148 # define FMT_END_NAMESPACE }}
149 # else
150 # define FMT_INLINE_NAMESPACE namespace
151 # define FMT_END_NAMESPACE } using namespace v5; }
152 # endif
153 # define FMT_BEGIN_NAMESPACE namespace fmt { FMT_INLINE_NAMESPACE v5 {
154 #endif
155 
156 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
157 # ifdef FMT_EXPORT
158 # define FMT_API __declspec(dllexport)
159 # elif defined(FMT_SHARED)
160 # define FMT_API __declspec(dllimport)
161 # endif
162 #endif
163 #ifndef FMT_API
164 # define FMT_API
165 #endif
166 
167 #ifndef FMT_ASSERT
168 # define FMT_ASSERT(condition, message) assert((condition) && message)
169 #endif
170 
171 // libc++ supports string_view in pre-c++17.
172 #if (FMT_HAS_INCLUDE(<string_view>) && \
173  (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
174  (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
175 # include <string_view>
176 # define FMT_STRING_VIEW std::basic_string_view
177 #elif FMT_HAS_INCLUDE(<experimental/string_view>) && __cplusplus >= 201402L
178 # include <experimental/string_view>
179 # define FMT_STRING_VIEW std::experimental::basic_string_view
180 #endif
181 
182 // std::result_of is defined in <functional> in gcc 4.4.
183 #if FMT_GCC_VERSION && FMT_GCC_VERSION <= 404
184 # include <functional>
185 #endif
186 
188 namespace internal {
189 
190 // An implementation of declval for pre-C++11 compilers such as gcc 4.
191 template <typename T>
193 
194 template <typename>
195 struct result_of;
196 
197 template <typename F, typename... Args>
198 struct result_of<F(Args...)> {
199  // A workaround for gcc 4.4 that doesn't allow F to be a reference.
200  typedef typename std::result_of<
202 };
203 
204 // Casts nonnegative integer to unsigned.
205 template <typename Int>
207  FMT_ASSERT(value >= 0, "negative value");
208  return static_cast<typename std::make_unsigned<Int>::type>(value);
209 }
210 
211 /** A contiguous memory buffer with an optional growing ability. */
212 template <typename T>
214  private:
215  basic_buffer(const basic_buffer &) = delete;
216  void operator=(const basic_buffer &) = delete;
217 
218  T *ptr_;
219  std::size_t size_;
220  std::size_t capacity_;
221 
222  protected:
223  // Don't initialize ptr_ since it is not accessed to save a few cycles.
224  basic_buffer(std::size_t sz) FMT_NOEXCEPT: size_(sz), capacity_(sz) {}
225 
226  basic_buffer(T *p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0)
227  FMT_NOEXCEPT: ptr_(p), size_(sz), capacity_(cap) {}
228 
229  /** Sets the buffer data and capacity. */
230  void set(T *buf_data, std::size_t buf_capacity) FMT_NOEXCEPT {
231  ptr_ = buf_data;
232  capacity_ = buf_capacity;
233  }
234 
235  /** Increases the buffer capacity to hold at least *capacity* elements. */
236  virtual void grow(std::size_t capacity) = 0;
237 
238  public:
239  typedef T value_type;
240  typedef const T &const_reference;
241 
242  virtual ~basic_buffer() {}
243 
244  T *begin() FMT_NOEXCEPT { return ptr_; }
245  T *end() FMT_NOEXCEPT { return ptr_ + size_; }
246 
247  /** Returns the size of this buffer. */
248  std::size_t size() const FMT_NOEXCEPT { return size_; }
249 
250  /** Returns the capacity of this buffer. */
251  std::size_t capacity() const FMT_NOEXCEPT { return capacity_; }
252 
253  /** Returns a pointer to the buffer data. */
254  T *data() FMT_NOEXCEPT { return ptr_; }
255 
256  /** Returns a pointer to the buffer data. */
257  const T *data() const FMT_NOEXCEPT { return ptr_; }
258 
259  /**
260  Resizes the buffer. If T is a POD type new elements may not be initialized.
261  */
262  void resize(std::size_t new_size) {
263  reserve(new_size);
264  size_ = new_size;
265  }
266 
267  /** Clears this buffer. */
268  void clear() { size_ = 0; }
269 
270  /** Reserves space to store at least *capacity* elements. */
271  void reserve(std::size_t new_capacity) {
272  if (new_capacity > capacity_)
273  grow(new_capacity);
274  }
275 
276  void push_back(const T &value) {
277  reserve(size_ + 1);
278  ptr_[size_++] = value;
279  }
280 
281  /** Appends data to the end of the buffer. */
282  template <typename U>
283  void append(const U *begin, const U *end);
284 
285  T &operator[](std::size_t index) { return ptr_[index]; }
286  const T &operator[](std::size_t index) const { return ptr_[index]; }
287 };
288 
291 
292 // A container-backed buffer.
293 template <typename Container>
294 class container_buffer : public basic_buffer<typename Container::value_type> {
295  private:
296  Container &container_;
297 
298  protected:
299  void grow(std::size_t capacity) FMT_OVERRIDE {
300  container_.resize(capacity);
301  this->set(&container_[0], capacity);
302  }
303 
304  public:
305  explicit container_buffer(Container &c)
306  : basic_buffer<typename Container::value_type>(c.size()), container_(c) {}
307 };
308 
309 // Extracts a reference to the container from back_insert_iterator.
310 template <typename Container>
311 inline Container &get_container(std::back_insert_iterator<Container> it) {
312  typedef std::back_insert_iterator<Container> bi_iterator;
313  struct accessor: bi_iterator {
314  accessor(bi_iterator iter) : bi_iterator(iter) {}
315  using bi_iterator::container;
316  };
317  return *accessor(it).container;
318 }
319 
323 
324  // This function is intentionally not constexpr to give a compile-time error.
325  FMT_API void on_error(const char *message);
326 };
327 
328 template <typename T>
329 struct no_formatter_error : std::false_type {};
330 } // namespace internal
331 
332 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 405
333 template <typename... T>
334 struct is_constructible: std::false_type {};
335 #else
336 template <typename... T>
337 struct is_constructible : std::is_constructible<T...> {};
338 #endif
339 
340 /**
341  An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
342  subset of the API. ``fmt::basic_string_view`` is used for format strings even
343  if ``std::string_view`` is available to prevent issues when a library is
344  compiled with a different ``-std`` option than the client code (which is not
345  recommended).
346  */
347 template <typename Char>
349  private:
350  const Char *data_;
351  size_t size_;
352 
353  public:
354  typedef Char char_type;
355  typedef const Char *iterator;
356 
358 
359  /** Constructs a string reference object from a C string and a size. */
361  : data_(s), size_(count) {}
362 
363  /**
364  \rst
365  Constructs a string reference object from a C string computing
366  the size with ``std::char_traits<Char>::length``.
367  \endrst
368  */
369  basic_string_view(const Char *s)
370  : data_(s), size_(std::char_traits<Char>::length(s)) {}
371 
372  /** Constructs a string reference from a ``std::basic_string`` object. */
373  template <typename Alloc>
375  const std::basic_string<Char, Alloc> &s) FMT_NOEXCEPT
376  : data_(s.data()), size_(s.size()) {}
377 
378 #ifdef FMT_STRING_VIEW
379  FMT_CONSTEXPR basic_string_view(FMT_STRING_VIEW<Char> s) FMT_NOEXCEPT
380  : data_(s.data()), size_(s.size()) {}
381 #endif
382 
383  /** Returns a pointer to the string data. */
384  FMT_CONSTEXPR const Char *data() const { return data_; }
385 
386  /** Returns the string size. */
387  FMT_CONSTEXPR size_t size() const { return size_; }
388 
389  FMT_CONSTEXPR iterator begin() const { return data_; }
390  FMT_CONSTEXPR iterator end() const { return data_ + size_; }
391 
393  data_ += n;
394  size_ -= n;
395  }
396 
397  // Lexicographically compare this string reference to other.
398  int compare(basic_string_view other) const {
399  size_t str_size = size_ < other.size_ ? size_ : other.size_;
400  int result = std::char_traits<Char>::compare(data_, other.data_, str_size);
401  if (result == 0)
402  result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
403  return result;
404  }
405 
407  return lhs.compare(rhs) == 0;
408  }
410  return lhs.compare(rhs) != 0;
411  }
413  return lhs.compare(rhs) < 0;
414  }
416  return lhs.compare(rhs) <= 0;
417  }
419  return lhs.compare(rhs) > 0;
420  }
422  return lhs.compare(rhs) >= 0;
423  }
424 };
425 
428 
429 /**
430  \rst
431  The function ``to_string_view`` adapts non-intrusively any kind of string or
432  string-like type if the user provides a (possibly templated) overload of
433  ``to_string_view`` which takes an instance of the string class
434  ``StringType<Char>`` and returns a ``fmt::basic_string_view<Char>``.
435  The conversion function must live in the very same namespace as
436  ``StringType<Char>`` to be picked up by ADL. Non-templated string types
437  like f.e. QString must return a ``basic_string_view`` with a fixed matching
438  char type.
439 
440  **Example**::
441 
442  namespace my_ns {
443  inline string_view to_string_view(const my_string &s) {
444  return { s.data(), s.length() };
445  }
446  }
447 
448  std::string message = fmt::format(my_string("The answer is {}"), 42);
449  \endrst
450  */
451 template <typename Char>
454 
455 template <typename Char>
457  to_string_view(const std::basic_string<Char> &s) { return s; }
458 
459 template <typename Char>
460 inline basic_string_view<Char> to_string_view(const Char *s) { return s; }
461 
462 #ifdef FMT_STRING_VIEW
463 template <typename Char>
465  to_string_view(FMT_STRING_VIEW<Char> s) { return s; }
466 #endif
467 
468 // A base class for compile-time strings. It is defined in the fmt namespace to
469 // make formatting functions visible via ADL, e.g. format(fmt("{}"), 42).
470 struct compile_string {};
471 
472 template <typename S>
473 struct is_compile_string : std::is_base_of<compile_string, S> {};
474 
475 template <
476  typename S,
477  typename Enable = typename std::enable_if<is_compile_string<S>::value>::type>
479  to_string_view(const S &s) { return s; }
480 
481 template <typename Context>
483 
484 template <typename Context>
486 
487 // A formatter for objects of type T.
488 template <typename T, typename Char = char, typename Enable = void>
489 struct formatter {
491  "don't know how to format the type, include fmt/ostream.h if it provides "
492  "an operator<< that should be used");
493 
494  // The following functions are not defined intentionally.
495  template <typename ParseContext>
496  typename ParseContext::iterator parse(ParseContext &);
497  template <typename FormatContext>
498  auto format(const T &val, FormatContext &ctx) -> decltype(ctx.out());
499 };
500 
501 template <typename T, typename Char, typename Enable = void>
502 struct convert_to_int: std::integral_constant<
503  bool, !std::is_arithmetic<T>::value && std::is_convertible<T, int>::value> {};
504 
505 namespace internal {
506 
507 struct dummy_string_view { typedef void char_type; };
510 
511 // Specifies whether S is a string type convertible to fmt::basic_string_view.
512 template <typename S>
513 struct is_string : std::integral_constant<bool, !std::is_same<
514  dummy_string_view, decltype(to_string_view(declval<S>()))>::value> {};
515 
516 template <typename S>
517 struct char_t {
518  typedef decltype(to_string_view(declval<S>())) result;
519  typedef typename result::char_type type;
520 };
521 
522 template <typename Char>
524 
525 template <typename T, typename Char>
526 struct named_arg;
527 
528 enum type {
530  // Integer types should go first,
533  // followed by floating-point types.
536 };
537 
539  FMT_ASSERT(t != internal::named_arg_type, "invalid argument type");
541 }
542 
544  FMT_ASSERT(t != internal::named_arg_type, "invalid argument type");
546 }
547 
548 template <typename Char>
549 struct string_value {
550  const Char *value;
551  std::size_t size;
552 };
553 
554 template <typename Context>
555 struct custom_value {
556  const void *value;
557  void (*format)(const void *arg, Context &ctx);
558 };
559 
560 // A formatting argument value.
561 template <typename Context>
562 class value {
563  public:
564  typedef typename Context::char_type char_type;
565 
566  union {
568  unsigned uint_value;
569  long long long_long_value;
570  unsigned long long ulong_long_value;
571  double double_value;
572  long double long_double_value;
573  const void *pointer;
578  };
579 
580  FMT_CONSTEXPR value(int val = 0) : int_value(val) {}
581  value(unsigned val) { uint_value = val; }
582  value(long long val) { long_long_value = val; }
583  value(unsigned long long val) { ulong_long_value = val; }
584  value(double val) { double_value = val; }
585  value(long double val) { long_double_value = val; }
586  value(const char_type *val) { string.value = val; }
587  value(const signed char *val) {
589  "incompatible string types");
590  sstring.value = val;
591  }
592  value(const unsigned char *val) {
594  "incompatible string types");
595  ustring.value = val;
596  }
598  string.value = val.data();
599  string.size = val.size();
600  }
601  value(const void *val) { pointer = val; }
602 
603  template <typename T>
604  explicit value(const T &val) {
605  custom.value = &val;
606  custom.format = &format_custom_arg<T>;
607  }
608 
610  return *static_cast<const named_arg_base<char_type>*>(pointer);
611  }
612 
613  private:
614  // Formats an argument of a custom type, such as a user-defined class.
615  template <typename T>
616  static void format_custom_arg(const void *arg, Context &ctx) {
617  // Get the formatter type through the context to allow different contexts
618  // have different extension points, e.g. `formatter<T>` for `format` and
619  // `printf_formatter<T>` for `printf`.
620  typename Context::template formatter_type<T>::type f;
621  auto &&parse_ctx = ctx.parse_context();
622  parse_ctx.advance_to(f.parse(parse_ctx));
623  ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
624  }
625 };
626 
627 // Value initializer used to delay conversion to value and reduce memory churn.
628 template <typename Context, typename T, type TYPE>
629 struct init {
631  static const type type_tag = TYPE;
632 
633  FMT_CONSTEXPR init(const T &v) : val(v) {}
634  FMT_CONSTEXPR operator value<Context>() const { return value<Context>(val); }
635 };
636 
637 template <typename Context, typename T>
639 
640 #define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \
641  template <typename C> \
642  FMT_CONSTEXPR init<C, ValueType, TAG> make_value(ArgType val) { \
643  return static_cast<ValueType>(val); \
644  }
645 
646 #define FMT_MAKE_VALUE_SAME(TAG, Type) \
647  template <typename C> \
648  FMT_CONSTEXPR init<C, Type, TAG> make_value(Type val) { return val; }
649 
650 FMT_MAKE_VALUE(bool_type, bool, int)
651 FMT_MAKE_VALUE(int_type, short, int)
652 FMT_MAKE_VALUE(uint_type, unsigned short, unsigned)
653 FMT_MAKE_VALUE_SAME(int_type, int)
654 FMT_MAKE_VALUE_SAME(uint_type, unsigned)
655 
656 // To minimize the number of types we need to deal with, long is translated
657 // either to int or to long long depending on its size.
658 typedef std::conditional<sizeof(long) == sizeof(int), int, long long>::type
661  (sizeof(long) == sizeof(int) ? int_type : long_long_type), long, long_type)
662 typedef std::conditional<sizeof(unsigned long) == sizeof(unsigned),
663  unsigned, unsigned long long>::type ulong_type;
665  (sizeof(unsigned long) == sizeof(unsigned) ? uint_type : ulong_long_type),
666  unsigned long, ulong_type)
667 
668 FMT_MAKE_VALUE_SAME(long_long_type, long long)
669 FMT_MAKE_VALUE_SAME(ulong_long_type, unsigned long long)
670 FMT_MAKE_VALUE(int_type, signed char, int)
671 FMT_MAKE_VALUE(uint_type, unsigned char, unsigned)
672 
673 // This doesn't use FMT_MAKE_VALUE because of ambiguity in gcc 4.4.
674 template <typename C, typename Char>
675 FMT_CONSTEXPR typename std::enable_if<
676  std::is_same<typename C::char_type, Char>::value,
677  init<C, int, char_type>>::type make_value(Char val) { return val; }
678 
679 template <typename C>
680 FMT_CONSTEXPR typename std::enable_if<
683 
684 FMT_MAKE_VALUE(double_type, float, double)
687 
688 // Formatting of wide strings into a narrow buffer and multibyte strings
689 // into a wide buffer is disallowed (https://github.com/fmtlib/fmt/pull/606).
691  const typename C::char_type*)
692 FMT_MAKE_VALUE(cstring_type, const typename C::char_type*,
693  const typename C::char_type*)
694 
695 FMT_MAKE_VALUE(cstring_type, signed char*, const signed char*)
696 FMT_MAKE_VALUE_SAME(cstring_type, const signed char*)
697 FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*)
698 FMT_MAKE_VALUE_SAME(cstring_type, const unsigned char*)
699 FMT_MAKE_VALUE_SAME(string_type, basic_string_view<typename C::char_type>)
700 FMT_MAKE_VALUE(string_type,
701  typename basic_string_view<typename C::char_type>::type,
702  basic_string_view<typename C::char_type>)
703 FMT_MAKE_VALUE(string_type, const std::basic_string<typename C::char_type>&,
704  basic_string_view<typename C::char_type>)
705 FMT_MAKE_VALUE(pointer_type, void*, const void*)
706 FMT_MAKE_VALUE_SAME(pointer_type, const void*)
707 
708 #if FMT_USE_NULLPTR
709 FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
710 #endif
711 
712 // Formatting of arbitrary pointers is disallowed. If you want to output a
713 // pointer cast it to "void *" or "const void *". In particular, this forbids
714 // formatting of "[const] volatile char *" which is printed as bool by
715 // iostreams.
716 template <typename C, typename T>
718  make_value(const T *) {
719  static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
720 }
721 
722 template <typename C, typename T>
723 inline typename std::enable_if<
725  init<C, int, int_type>>::type
726  make_value(const T &val) { return static_cast<int>(val); }
727 
728 template <typename C, typename T, typename Char = typename C::char_type>
729 inline typename std::enable_if<
732  init<C, basic_string_view<Char>, string_type>>::type
733  make_value(const T &val) { return basic_string_view<Char>(val); }
734 
735 template <typename C, typename T, typename Char = typename C::char_type>
736 inline typename std::enable_if<
738  !std::is_convertible<T, basic_string_view<Char>>::value &&
741  // Implicit conversion to std::string is not handled here because it's
742  // unsafe: https://github.com/fmtlib/fmt/issues/729
743  init<C, const T &, custom_type>>::type
744  make_value(const T &val) { return val; }
745 
746 template <typename C, typename T>
747 init<C, const void*, named_arg_type>
749  basic_format_arg<C> arg = make_arg<C>(val.value);
750  std::memcpy(val.data, &arg, sizeof(arg));
751  return static_cast<const void*>(&val);
752 }
753 
754 template <typename C, typename S>
755 FMT_CONSTEXPR11 typename std::enable_if<
757  init<C, basic_string_view<typename C::char_type>, string_type>>::type
758  make_value(const S &val) {
759  // Handle adapted strings.
760  static_assert(std::is_same<
761  typename C::char_type, typename internal::char_t<S>::type>::value,
762  "mismatch between char-types of context and argument");
763  return to_string_view(val);
764 }
765 
766 // Maximum number of arguments with packed types.
767 enum { max_packed_args = 15 };
768 
769 template <typename Context>
770 class arg_map;
771 } // namespace internal
772 
773 // A formatting argument. It is a trivially copyable/constructible type to
774 // allow storage in basic_memory_buffer.
775 template <typename Context>
776 class basic_format_arg {
777  private:
779  internal::type type_;
780 
781  template <typename ContextType, typename T>
783  internal::make_arg(const T &value);
784 
785  template <typename Visitor, typename Ctx>
787  visit_format_arg(Visitor &&vis, const basic_format_arg<Ctx> &arg);
788 
789  friend class basic_format_args<Context>;
790  friend class internal::arg_map<Context>;
791 
792  typedef typename Context::char_type char_type;
793 
794  public:
795  class handle {
796  public:
797  explicit handle(internal::custom_value<Context> custom): custom_(custom) {}
798 
799  void format(Context &ctx) const { custom_.format(custom_.value, ctx); }
800 
801  private:
803  };
804 
805  FMT_CONSTEXPR basic_format_arg() : type_(internal::none_type) {}
806 
807  FMT_EXPLICIT operator bool() const FMT_NOEXCEPT {
808  return type_ != internal::none_type;
809  }
810 
811  internal::type type() const { return type_; }
812 
813  bool is_integral() const { return internal::is_integral(type_); }
814  bool is_arithmetic() const { return internal::is_arithmetic(type_); }
815 };
816 
817 struct monostate {};
818 
819 /**
820  \rst
821  Visits an argument dispatching to the appropriate visit method based on
822  the argument type. For example, if the argument type is ``double`` then
823  ``vis(value)`` will be called with the value of type ``double``.
824  \endrst
825  */
826 template <typename Visitor, typename Context>
828  visit_format_arg(Visitor &&vis, const basic_format_arg<Context> &arg) {
829  typedef typename Context::char_type char_type;
830  switch (arg.type_) {
831  case internal::none_type:
832  break;
834  FMT_ASSERT(false, "invalid argument type");
835  break;
836  case internal::int_type:
837  return vis(arg.value_.int_value);
838  case internal::uint_type:
839  return vis(arg.value_.uint_value);
841  return vis(arg.value_.long_long_value);
843  return vis(arg.value_.ulong_long_value);
844  case internal::bool_type:
845  return vis(arg.value_.int_value != 0);
846  case internal::char_type:
847  return vis(static_cast<char_type>(arg.value_.int_value));
849  return vis(arg.value_.double_value);
851  return vis(arg.value_.long_double_value);
853  return vis(arg.value_.string.value);
855  return vis(basic_string_view<char_type>(
856  arg.value_.string.value, arg.value_.string.size));
858  return vis(arg.value_.pointer);
860  return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
861  }
862  return vis(monostate());
863 }
864 
865 template <typename Visitor, typename Context>
867  visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
868  return visit_format_arg(std::forward<Visitor>(vis), arg);
869 }
870 
871 // Parsing context consisting of a format string range being parsed and an
872 // argument counter for automatic indexing.
873 template <typename Char, typename ErrorHandler = internal::error_handler>
875  private:
876  basic_string_view<Char> format_str_;
877  int next_arg_id_;
878 
879  public:
880  typedef Char char_type;
882 
885  : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {}
886 
887  // Returns an iterator to the beginning of the format string range being
888  // parsed.
890  return format_str_.begin();
891  }
892 
893  // Returns an iterator past the end of the format string range being parsed.
894  FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT { return format_str_.end(); }
895 
896  // Advances the begin iterator to ``it``.
898  format_str_.remove_prefix(internal::to_unsigned(it - begin()));
899  }
900 
901  // Returns the next argument index.
902  FMT_CONSTEXPR unsigned next_arg_id();
903 
904  FMT_CONSTEXPR bool check_arg_id(unsigned) {
905  if (next_arg_id_ > 0) {
906  on_error("cannot switch from automatic to manual argument indexing");
907  return false;
908  }
909  next_arg_id_ = -1;
910  return true;
911  }
913 
914  FMT_CONSTEXPR void on_error(const char *message) {
915  ErrorHandler::on_error(message);
916  }
917 
918  FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; }
919 };
920 
923 
924 // DEPRECATED!
927 
928 namespace internal {
929 // A map from argument names to their values for named arguments.
930 template <typename Context>
931 class arg_map {
932  private:
933  arg_map(const arg_map &) = delete;
934  void operator=(const arg_map &) = delete;
935 
936  typedef typename Context::char_type char_type;
937 
938  struct entry {
941  };
942 
943  entry *map_;
944  unsigned size_;
945 
946  void push_back(value<Context> val) {
947  const internal::named_arg_base<char_type> &named = val.as_named_arg();
948  map_[size_] = entry{named.name, named.template deserialize<Context>()};
949  ++size_;
950  }
951 
952  public:
953  arg_map() : map_(FMT_NULL), size_(0) {}
954  void init(const basic_format_args<Context> &args);
955  ~arg_map() { delete [] map_; }
956 
958  // The list is unsorted, so just return the first matching name.
959  for (entry *it = map_, *end = map_ + size_; it != end; ++it) {
960  if (it->name == name)
961  return it->arg;
962  }
963  return {};
964  }
965 };
966 
967 // A type-erased reference to an std::locale to avoid heavy <locale> include.
968 class locale_ref {
969  private:
970  const void *locale_; // A type-erased pointer to std::locale.
971  friend class locale;
972 
973  public:
974  locale_ref() : locale_(FMT_NULL) {}
975 
976  template <typename Locale>
977  explicit locale_ref(const Locale &loc);
978 
979  template <typename Locale>
980  Locale get() const;
981 };
982 
983 template <typename OutputIt, typename Context, typename Char>
985  public:
986  typedef OutputIt iterator;
987 
988  private:
989  basic_parse_context<Char> parse_context_;
990  iterator out_;
992  locale_ref loc_;
993 
994  protected:
995  typedef Char char_type;
997 
998  context_base(OutputIt out, basic_string_view<char_type> format_str,
1000  locale_ref loc = locale_ref())
1001  : parse_context_(format_str), out_(out), args_(ctx_args), loc_(loc) {}
1002 
1003  // Returns the argument with specified index.
1004  format_arg do_get_arg(unsigned arg_id) {
1005  format_arg arg = args_.get(arg_id);
1006  if (!arg)
1007  parse_context_.on_error("argument index out of range");
1008  return arg;
1009  }
1010 
1011  // Checks if manual indexing is used and returns the argument with
1012  // specified index.
1013  format_arg get_arg(unsigned arg_id) {
1014  return this->parse_context().check_arg_id(arg_id) ?
1015  this->do_get_arg(arg_id) : format_arg();
1016  }
1017 
1018  public:
1019  basic_parse_context<char_type> &parse_context() { return parse_context_; }
1020  basic_format_args<Context> args() const { return args_; }
1021 
1023  return parse_context_.error_handler();
1024  }
1025 
1026  void on_error(const char *message) { parse_context_.on_error(message); }
1027 
1028  // Returns an iterator to the beginning of the output range.
1029  iterator out() { return out_; }
1030  iterator begin() { return out_; } // deprecated
1031 
1032  // Advances the begin iterator to ``it``.
1033  void advance_to(iterator it) { out_ = it; }
1034 
1035  locale_ref locale() { return loc_; }
1036 };
1037 
1038 template <typename Context, typename T>
1039 struct get_type {
1040  typedef decltype(make_value<Context>(
1042  static const type value = value_type::type_tag;
1043 };
1044 
1045 template <typename Context>
1046 FMT_CONSTEXPR11 unsigned long long get_types() { return 0; }
1047 
1048 template <typename Context, typename Arg, typename... Args>
1049 FMT_CONSTEXPR11 unsigned long long get_types() {
1050  return get_type<Context, Arg>::value | (get_types<Context, Args...>() << 4);
1051 }
1052 
1053 template <typename Context, typename T>
1056  arg.type_ = get_type<Context, T>::value;
1057  arg.value_ = make_value<Context>(value);
1058  return arg;
1059 }
1060 
1061 template <bool IS_PACKED, typename Context, typename T>
1062 inline typename std::enable_if<IS_PACKED, value<Context>>::type
1063  make_arg(const T &value) {
1064  return make_value<Context>(value);
1065 }
1066 
1067 template <bool IS_PACKED, typename Context, typename T>
1068 inline typename std::enable_if<!IS_PACKED, basic_format_arg<Context>>::type
1069  make_arg(const T &value) {
1070  return make_arg<Context>(value);
1071 }
1072 } // namespace internal
1073 
1074 // Formatting context.
1075 template <typename OutputIt, typename Char>
1077  public internal::context_base<
1078  OutputIt, basic_format_context<OutputIt, Char>, Char> {
1079  public:
1080  /** The character type for the output. */
1081  typedef Char char_type;
1082 
1083  // using formatter_type = formatter<T, char_type>;
1084  template <typename T>
1086 
1087  private:
1089 
1090  basic_format_context(const basic_format_context &) = delete;
1091  void operator=(const basic_format_context &) = delete;
1092 
1094  typedef typename base::format_arg format_arg;
1095  using base::get_arg;
1096 
1097  public:
1098  using typename base::iterator;
1099 
1100  /**
1101  Constructs a ``basic_format_context`` object. References to the arguments are
1102  stored in the object so make sure they have appropriate lifetimes.
1103  */
1107  : base(out, format_str, ctx_args, loc) {}
1108 
1110  return this->do_get_arg(this->parse_context().next_arg_id());
1111  }
1112  format_arg get_arg(unsigned arg_id) { return this->do_get_arg(arg_id); }
1113 
1114  // Checks if manual indexing is used and returns the argument with the
1115  // specified name.
1116  format_arg get_arg(basic_string_view<char_type> name);
1117 };
1118 
1119 template <typename Char>
1121  typedef basic_format_context<
1122  std::back_insert_iterator<internal::basic_buffer<Char>>, Char> type;
1123 };
1126 
1127 /**
1128  \rst
1129  An array of references to arguments. It can be implicitly converted into
1130  `~fmt::basic_format_args` for passing into type-erased formatting functions
1131  such as `~fmt::vformat`.
1132  \endrst
1133  */
1134 template <typename Context, typename ...Args>
1136  private:
1137  static const size_t NUM_ARGS = sizeof...(Args);
1138 
1139  // Packed is a macro on MinGW so use IS_PACKED instead.
1140  static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args;
1141 
1142  typedef typename std::conditional<IS_PACKED,
1144 
1145  // If the arguments are not packed, add one more element to mark the end.
1146  static const size_t DATA_SIZE =
1147  NUM_ARGS + (IS_PACKED && NUM_ARGS != 0 ? 0 : 1);
1148  value_type data_[DATA_SIZE];
1149 
1150  friend class basic_format_args<Context>;
1151 
1152  static FMT_CONSTEXPR11 long long get_types() {
1153  return IS_PACKED ?
1154  static_cast<long long>(internal::get_types<Context, Args...>()) :
1155  -static_cast<long long>(NUM_ARGS);
1156  }
1157 
1158  public:
1159 #if FMT_USE_CONSTEXPR11
1160  static FMT_CONSTEXPR11 long long TYPES = get_types();
1161 #else
1162  static const long long TYPES;
1163 #endif
1164 
1165 #if (FMT_GCC_VERSION && FMT_GCC_VERSION <= 405) || \
1166  (FMT_MSC_VER && FMT_MSC_VER <= 1800)
1167  // Workaround array initialization issues in gcc <= 4.5 and MSVC <= 2013.
1168  format_arg_store(const Args &... args) {
1169  value_type init[DATA_SIZE] =
1170  {internal::make_arg<IS_PACKED, Context>(args)...};
1171  std::memcpy(data_, init, sizeof(init));
1172  }
1173 #else
1174  format_arg_store(const Args &... args)
1175  : data_{internal::make_arg<IS_PACKED, Context>(args)...} {}
1176 #endif
1177 };
1178 
1179 #if !FMT_USE_CONSTEXPR11
1180 template <typename Context, typename ...Args>
1181 const long long format_arg_store<Context, Args...>::TYPES = get_types();
1182 #endif
1183 
1184 /**
1185  \rst
1186  Constructs an `~fmt::format_arg_store` object that contains references to
1187  arguments and can be implicitly converted to `~fmt::format_args`. `Context`
1188  can be omitted in which case it defaults to `~fmt::context`.
1189  \endrst
1190  */
1191 template <typename Context = format_context, typename ...Args>
1192 inline format_arg_store<Context, Args...>
1193  make_format_args(const Args &... args) { return {args...}; }
1194 
1195 /** Formatting arguments. */
1196 template <typename Context>
1197 class basic_format_args {
1198  public:
1199  typedef unsigned size_type;
1201 
1202  private:
1203  // To reduce compiled code size per formatting function call, types of first
1204  // max_packed_args arguments are passed in the types_ field.
1205  unsigned long long types_;
1206  union {
1207  // If the number of arguments is less than max_packed_args, the argument
1208  // values are stored in values_, otherwise they are stored in args_.
1209  // This is done to reduce compiled code size as storing larger objects
1210  // may require more code (at least on x86-64) even if the same amount of
1211  // data is actually copied to stack. It saves ~10% on the bloat test.
1214  };
1215 
1216  typename internal::type type(unsigned index) const {
1217  unsigned shift = index * 4;
1218  unsigned long long mask = 0xf;
1219  return static_cast<typename internal::type>(
1220  (types_ & (mask << shift)) >> shift);
1221  }
1222 
1223  friend class internal::arg_map<Context>;
1224 
1225  void set_data(const internal::value<Context> *values) { values_ = values; }
1226  void set_data(const format_arg *args) { args_ = args; }
1227 
1228  format_arg do_get(size_type index) const {
1229  format_arg arg;
1230  long long signed_types = static_cast<long long>(types_);
1231  if (signed_types < 0) {
1232  unsigned long long num_args =
1233  static_cast<unsigned long long>(-signed_types);
1234  if (index < num_args)
1235  arg = args_[index];
1236  return arg;
1237  }
1238  if (index > internal::max_packed_args)
1239  return arg;
1240  arg.type_ = type(index);
1241  if (arg.type_ == internal::none_type)
1242  return arg;
1243  internal::value<Context> &val = arg.value_;
1244  val = values_[index];
1245  return arg;
1246  }
1247 
1248  public:
1249  basic_format_args() : types_(0) {}
1250 
1251  /**
1252  \rst
1253  Constructs a `basic_format_args` object from `~fmt::format_arg_store`.
1254  \endrst
1255  */
1256  template <typename... Args>
1258  : types_(static_cast<unsigned long long>(store.TYPES)) {
1259  set_data(store.data_);
1260  }
1261 
1262  /**
1263  \rst
1264  Constructs a `basic_format_args` object from a dynamic set of arguments.
1265  \endrst
1266  */
1268  : types_(-static_cast<int64_t>(count)) {
1269  set_data(args);
1270  }
1271 
1272  /** Returns the argument at specified index. */
1274  format_arg arg = do_get(index);
1275  if (arg.type_ == internal::named_arg_type)
1276  arg = arg.value_.as_named_arg().template deserialize<Context>();
1277  return arg;
1278  }
1279 
1280  unsigned max_size() const {
1281  long long signed_types = static_cast<long long>(types_);
1282  return static_cast<unsigned>(
1283  signed_types < 0 ?
1284  -signed_types : static_cast<long long>(internal::max_packed_args));
1285  }
1286 };
1287 
1288 /** An alias to ``basic_format_args<context>``. */
1289 // It is a separate type rather than a typedef to make symbols readable.
1290 struct format_args : basic_format_args<format_context> {
1291  template <typename ...Args>
1292  format_args(Args &&... arg)
1293  : basic_format_args<format_context>(std::forward<Args>(arg)...) {}
1294 };
1295 struct wformat_args : basic_format_args<wformat_context> {
1296  template <typename ...Args>
1297  wformat_args(Args &&... arg)
1298  : basic_format_args<wformat_context>(std::forward<Args>(arg)...) {}
1299 };
1300 
1301 #ifndef FMT_USE_ALIAS_TEMPLATES
1302 # define FMT_USE_ALIAS_TEMPLATES FMT_HAS_FEATURE(cxx_alias_templates)
1303 #endif
1304 #if FMT_USE_ALIAS_TEMPLATES
1305 /** String's character type. */
1306 template <typename S>
1309 #define FMT_CHAR(S) fmt::char_t<S>
1310 
1311 template <typename S, typename T>
1312 using enable_if_string_t =
1314 #define FMT_ENABLE_IF_STRING(S, T) enable_if_string_t<S, T>
1315 #else
1316 template <typename S>
1317 struct char_t : std::enable_if<
1318  internal::is_string<S>::value, typename internal::char_t<S>::type> {};
1319 #define FMT_CHAR(S) typename char_t<S>::type
1320 
1321 #define FMT_ENABLE_IF_STRING(S, T) \
1322  typename std::enable_if<internal::is_string<S>::value, T>::type
1323 #endif
1324 
1325 namespace internal {
1326 template <typename Char>
1327 struct named_arg_base {
1329 
1330  // Serialized value<context>.
1331  mutable char data[
1333 
1335 
1336  template <typename Context>
1339  std::memcpy(&arg, data, sizeof(basic_format_arg<Context>));
1340  return arg;
1341  }
1342 };
1343 
1344 template <typename T, typename Char>
1345 struct named_arg : named_arg_base<Char> {
1346  const T &value;
1347 
1349  : named_arg_base<Char>(name), value(val) {}
1350 };
1351 
1352 template <typename... Args, typename S>
1353 inline typename std::enable_if<!is_compile_string<S>::value>::type
1354  check_format_string(const S &) {}
1355 template <typename... Args, typename S>
1358 
1359 template <typename S, typename... Args>
1361  typename buffer_context<FMT_CHAR(S)>::type, Args...> {
1363 
1364  checked_args(const S &format_str, const Args &... args):
1365  format_arg_store<context, Args...>(args...) {
1366  internal::check_format_string<Args...>(format_str);
1367  }
1368 
1369  basic_format_args<context> operator*() const { return *this; }
1370 };
1371 
1372 template <typename Char>
1373 std::basic_string<Char> vformat(
1374  basic_string_view<Char> format_str,
1376 
1377 template <typename Char>
1381 }
1382 
1383 /**
1384  \rst
1385  Returns a named argument to be used in a formatting function.
1386 
1387  **Example**::
1388 
1389  fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23));
1390  \endrst
1391  */
1392 template <typename T>
1393 inline internal::named_arg<T, char> arg(string_view name, const T &arg) {
1394  return {name, arg};
1395 }
1396 
1397 template <typename T>
1398 inline internal::named_arg<T, wchar_t> arg(wstring_view name, const T &arg) {
1399  return {name, arg};
1400 }
1401 
1402 // Disable nested named arguments, e.g. ``arg("a", arg("b", 42))``.
1403 template <typename S, typename T, typename Char>
1404 void arg(S, internal::named_arg<T, Char>) = delete;
1405 
1406 template <typename Container>
1407 struct is_contiguous: std::false_type {};
1408 
1409 template <typename Char>
1410 struct is_contiguous<std::basic_string<Char> >: std::true_type {};
1411 
1412 template <typename Char>
1413 struct is_contiguous<internal::basic_buffer<Char> >: std::true_type {};
1414 
1415 /** Formats a string and writes the output to ``out``. */
1416 template <typename Container, typename S>
1417 typename std::enable_if<
1418  is_contiguous<Container>::value, std::back_insert_iterator<Container>>::type
1420  std::back_insert_iterator<Container> out,
1421  const S &format_str,
1422  basic_format_args<typename buffer_context<FMT_CHAR(S)>::type> args) {
1424  internal::vformat_to(buf, to_string_view(format_str), args);
1425  return out;
1426 }
1427 
1428 template <typename Container, typename S, typename... Args>
1429 inline typename std::enable_if<
1430  is_contiguous<Container>::value && internal::is_string<S>::value,
1431  std::back_insert_iterator<Container>>::type
1432  format_to(std::back_insert_iterator<Container> out, const S &format_str,
1433  const Args &... args) {
1434  internal::checked_args<S, Args...> ca(format_str, args...);
1435  return vformat_to(out, to_string_view(format_str), *ca);
1436 }
1437 
1438 template <typename S, typename Char = FMT_CHAR(S)>
1439 inline std::basic_string<Char> vformat(
1440  const S &format_str,
1442  return internal::vformat(to_string_view(format_str), args);
1443 }
1444 
1445 /**
1446  \rst
1447  Formats arguments and returns the result as a string.
1448 
1449  **Example**::
1450 
1451  #include <fmt/core.h>
1452  std::string message = fmt::format("The answer is {}", 42);
1453  \endrst
1454 */
1455 template <typename S, typename... Args>
1456 inline std::basic_string<FMT_CHAR(S)> format(
1457  const S &format_str, const Args &... args) {
1458  return internal::vformat(
1459  to_string_view(format_str),
1460  *internal::checked_args<S, Args...>(format_str, args...));
1461 }
1462 
1463 FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
1464 FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args);
1465 
1466 /**
1467  \rst
1468  Prints formatted data to the file *f*. For wide format strings,
1469  *f* should be in wide-oriented mode set via ``fwide(f, 1)`` or
1470  ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows.
1471 
1472  **Example**::
1473 
1474  fmt::print(stderr, "Don't {}!", "panic");
1475  \endrst
1476  */
1477 template <typename S, typename... Args>
1478 inline FMT_ENABLE_IF_STRING(S, void)
1479  print(std::FILE *f, const S &format_str, const Args &... args) {
1480  vprint(f, to_string_view(format_str),
1481  internal::checked_args<S, Args...>(format_str, args...));
1482 }
1483 
1484 FMT_API void vprint(string_view format_str, format_args args);
1485 FMT_API void vprint(wstring_view format_str, wformat_args args);
1486 
1487 /**
1488  \rst
1489  Prints formatted data to ``stdout``.
1490 
1491  **Example**::
1492 
1493  fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
1494  \endrst
1495  */
1496 template <typename S, typename... Args>
1497 inline FMT_ENABLE_IF_STRING(S, void)
1498  print(const S &format_str, const Args &... args) {
1499  vprint(to_string_view(format_str),
1500  internal::checked_args<S, Args...>(format_str, args...));
1501 }
1503 
1504 #endif // FMT_CORE_H_
OutputIt iterator
Definition: core.h:986
GLdouble s
Definition: glew.h:1390
T & operator[](std::size_t index)
Definition: core.h:285
FMT_CONSTEXPR bool check_arg_id(unsigned)
Definition: core.h:904
virtual ~basic_buffer()
Definition: core.h:242
value(const signed char *val)
Definition: core.h:587
result::char_type type
Definition: core.h:519
Char char_type
Definition: core.h:354
GLsizeiptr size
Definition: glew.h:1681
format_arg get_arg(unsigned arg_id)
Definition: core.h:1013
Container & get_container(std::back_insert_iterator< Container > it)
Definition: core.h:311
const T & const_reference
Definition: core.h:240
GLuint const GLchar * name
Definition: glew.h:1814
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT
Definition: core.h:357
std::conditional< sizeof(long)==sizeof(int), int, long long >::type long_type
Definition: core.h:659
basic_parse_context< wchar_t > wformat_parse_context
Definition: core.h:922
value(const unsigned char *val)
Definition: core.h:592
handle(internal::custom_value< Context > custom)
Definition: core.h:797
format_args(Args &&...arg)
Definition: core.h:1292
T * begin() FMT_NOEXCEPT
Definition: core.h:244
value(const T &val)
Definition: core.h:604
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
Definition: format.h:251
const Args & args
Definition: printf.h:628
checked_args(const S &format_str, const Args &...args)
Definition: core.h:1364
GLuint index
Definition: glew.h:1814
FMT_API void on_error(const char *message)
Definition: format-inl.h:928
format_arg do_get_arg(unsigned arg_id)
Definition: core.h:1004
GLuint const GLfloat * val
Definition: glew.h:2794
basic_string_view< Char >::iterator iterator
Definition: core.h:881
auto format(const T &val, FormatContext &ctx) -> decltype(ctx.out())
internal::named_arg< T, char > arg(string_view name, const T &arg)
Definition: core.h:1393
const named_arg_base< char_type > & as_named_arg()
Definition: core.h:609
void append(const U *begin, const U *end)
Definition: format.h:394
basic_format_arg< Context > format_arg
Definition: core.h:996
const T & operator[](std::size_t index) const
Definition: core.h:286
unsigned uint_value
Definition: core.h:568
FMT_CONSTEXPR error_handler(const error_handler &)
Definition: core.h:322
GLint GLsizei const GLuint64 * values
Definition: glew.h:3612
void on_error(const char *message)
Definition: core.h:1026
basic_buffer(T *p=FMT_NULL, std::size_t sz=0, std::size_t cap=0) FMT_NOEXCEPT
Definition: core.h:226
FMT_CONSTEXPR error_handler()
Definition: core.h:321
std::add_rvalue_reference< T >::type declval() FMT_NOEXCEPT
basic_parse_context< wchar_t > wparse_context
Definition: core.h:926
named_arg_base(basic_string_view< Char > nm)
Definition: core.h:1334
#define FMT_CONSTEXPR11
Definition: core.h:80
basic_format_args< Context > args() const
Definition: core.h:1020
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
value(unsigned val)
Definition: core.h:581
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Alloc > &s) FMT_NOEXCEPT
Definition: core.h:374
const GLdouble * v
Definition: glew.h:1391
basic_string_view< wchar_t > wstring_view
Definition: core.h:427
GLenum GLint GLuint mask
Definition: glew.h:1845
friend bool operator<(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:412
buffer_context< char >::type format_context
Definition: core.h:1124
void check_arg_id(basic_string_view< Char >)
Definition: core.h:912
void resize(std::size_t new_size)
Definition: core.h:262
FMT_CONSTEXPR void on_error(const char *message)
Definition: core.h:914
#define FMT_MAKE_VALUE_SAME(TAG, Type)
Definition: core.h:646
const void * pointer
Definition: core.h:573
basic_buffer(std::size_t sz) FMT_NOEXCEPT
Definition: core.h:224
uint64 value_type
Definition: GA_PrimCompat.h:29
value(unsigned long long val)
Definition: core.h:583
FMT_CONSTEXPR basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
Definition: core.h:360
FMT_CONSTEXPR basic_format_arg< Context > make_arg(const T &value)
Definition: core.h:1054
#define FMT_END_NAMESPACE
Definition: core.h:151
FMT_CONSTEXPR size_t size() const
Definition: core.h:387
char data[sizeof(basic_format_arg< typename buffer_context< Char >::type >)]
Definition: core.h:1332
locale_ref locale()
Definition: core.h:1035
named_arg(basic_string_view< Char > name, const T &val)
Definition: core.h:1348
std::enable_if<!is_compile_string< S >::value >::type check_format_string(const S &)
Definition: core.h:1354
basic_buffer< wchar_t > wbuffer
Definition: core.h:290
std::result_of< typename std::remove_reference< F >::type(Args...)>::type type
Definition: core.h:201
iterator begin()
Definition: core.h:1030
int int_value
Definition: core.h:567
friend bool operator!=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:409
format_arg_store(const Args &...args)
Definition: core.h:1174
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
double double_value
Definition: core.h:571
const internal::value< Context > * values_
Definition: core.h:1212
std::enable_if< is_contiguous< Container >::value &&internal::is_string< S >::value, std::back_insert_iterator< Container > >::type format_to(std::back_insert_iterator< Container > out, const S &format_str, const Args &...args)
Definition: core.h:1432
container_buffer(Container &c)
Definition: core.h:305
basic_string_view(const Char *s)
Definition: core.h:369
value(const char_type *val)
Definition: core.h:586
T * data() FMT_NOEXCEPT
Definition: core.h:254
buffer_context< FMT_CHAR(S)>::type context
Definition: core.h:1362
value(basic_string_view< char_type > val)
Definition: core.h:597
virtual void grow(std::size_t capacity)=0
bool is_arithmetic() const
Definition: core.h:814
void advance_to(iterator it)
Definition: core.h:1033
buffer_context< Char >::type::iterator vformat_to(internal::basic_buffer< Char > &buf, basic_string_view< Char > format_str, basic_format_args< typename buffer_context< Char >::type > args)
Definition: format.h:3387
FMT_CONSTEXPR auto end(const C &c) -> decltype(c.end())
Definition: format.h:257
GLclampf f
Definition: glew.h:3499
dummy_string_view to_string_view(...)
const T * data() const FMT_NOEXCEPT
Definition: core.h:257
FMT_CONSTEXPR const Char * data() const
Definition: core.h:384
friend bool operator>=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:421
value(long double val)
Definition: core.h:585
basic_parse_context< char > format_parse_context
Definition: core.h:921
format_arg next_arg()
Definition: core.h:1109
value(long long val)
Definition: core.h:582
FMT_CONSTEXPR bool is_arithmetic(type t)
Definition: core.h:543
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< typename buffer_context< Char >::type > args)
Definition: format.h:3564
format_arg get_arg(unsigned arg_id)
Definition: core.h:1112
unsigned max_size() const
Definition: core.h:1280
FMT_CONSTEXPR bool is_integral(type t)
Definition: core.h:538
GLuint GLuint end
Definition: glew.h:1253
basic_format_arg< Context > format_arg
Definition: core.h:1200
basic_string_view< char > string_view
Definition: core.h:426
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
Definition: glew.h:2581
void
Definition: png.h:1083
buffer_context< wchar_t >::type wformat_context
Definition: core.h:1125
std::size_t size() const FMT_NOEXCEPT
Definition: core.h:248
GLsizei n
Definition: glew.h:4040
const GLfloat * c
Definition: glew.h:16296
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
void push_back(const T &value)
Definition: core.h:276
std::size_t capacity() const FMT_NOEXCEPT
Definition: core.h:251
basic_string_view< Char > name
Definition: core.h:1328
basic_format_args(const format_arg_store< Context, Args...> &store)
Definition: core.h:1257
#define FMT_API
Definition: core.h:164
void grow(std::size_t capacity) FMT_OVERRIDE
Definition: core.h:299
friend bool operator>(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:418
FMT_CONSTEXPR ErrorHandler error_handler() const
Definition: core.h:918
FMT_MAKE_VALUE((sizeof(long)==sizeof(int)?int_type:long_long_type), long, long_type) typedef std FMT_MAKE_VALUE((sizeof(unsigned long)==sizeof(unsigned)?uint_type:ulong_long_type), unsigned long, ulong_type) template< typename C
void reserve(std::size_t new_capacity)
Definition: core.h:271
unsigned size_type
Definition: core.h:1199
wformat_args(Args &&...arg)
Definition: core.h:1297
basic_buffer< char > buffer
Definition: core.h:289
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
internal::type type() const
Definition: core.h:811
FMT_CONSTEXPR void advance_to(iterator it)
Definition: core.h:897
format_arg_store< Context, Args...> make_format_args(const Args &...args)
Definition: core.h:1193
Definition: core.h:1317
FMT_MAKE_VALUE((sizeof(long)==sizeof(int)?int_type:long_long_type), long, long_type) typedef std Char FMT_CONSTEXPR std::enable_if< std::is_same< typename C::char_type, Char >::value, init< C, int, char_type > >::type make_value(Char val)
Definition: core.h:677
string_value< char_type > string
Definition: core.h:574
void init(const basic_format_args< Context > &args)
Definition: format.h:1359
FMT_CONSTEXPR value(int val=0)
Definition: core.h:580
GLenum cap
Definition: glew.h:11504
basic_format_context< std::back_insert_iterator< internal::basic_buffer< Char > >, Char > type
Definition: core.h:1122
long long long_long_value
Definition: core.h:569
#define FMT_CHAR(S)
Definition: core.h:1319
friend bool operator<=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:415
std::basic_string< FMT_CHAR(S)> format(const S &format_str, const Args &...args)
Definition: core.h:1456
basic_format_arg< Context > deserialize() const
Definition: core.h:1337
FMT_CONSTEXPR internal::result_of< Visitor(int)>::type visit(Visitor &&vis, const basic_format_arg< Context > &arg)
Definition: core.h:867
const void * value
Definition: core.h:556
GLfloat GLfloat p
Definition: glew.h:16321
#define FMT_NULL
Definition: core.h:107
OutputIt iterator
Definition: core.h:986
std::size_t size
Definition: core.h:551
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:206
#define FMT_CONSTEXPR
Definition: core.h:69
bool is_integral() const
Definition: core.h:813
context_base(OutputIt out, basic_string_view< char_type > format_str, basic_format_args< Context > ctx_args, locale_ref loc=locale_ref())
Definition: core.h:998
GLsizei const void * pointer
Definition: glew.h:1523
iterator out()
Definition: core.h:1029
value(const void *val)
Definition: core.h:601
friend bool operator==(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:406
#define FMT_EXPLICIT
Definition: core.h:98
FMT_CONSTEXPR basic_parse_context(basic_string_view< Char > format_str, ErrorHandler eh=ErrorHandler())
Definition: core.h:883
FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT
Definition: core.h:889
GLuint GLuint GLsizei count
Definition: glew.h:1253
const Char * iterator
Definition: core.h:355
void format(Context &ctx) const
Definition: core.h:799
#define FMT_ENABLE_IF_STRING(S, T)
Definition: core.h:1321
static const long long TYPES
Definition: core.h:1162
const format_arg * args_
Definition: core.h:1213
int compare(basic_string_view other) const
Definition: core.h:398
FMT_CONSTEXPR iterator end() const
Definition: core.h:390
GLuint64EXT * result
Definition: glew.h:14007
Helper template to let us tell if two types are the same.
Definition: fmath.h:74
#define FMT_NOEXCEPT
Definition: core.h:138
ParseContext::iterator parse(ParseContext &)
FMT_API void vprint(std::FILE *f, string_view format_str, format_args args)
Definition: format-inl.h:944
basic_format_arg< Context > find(basic_string_view< char_type > name) const
Definition: core.h:957
basic_format_context(OutputIt out, basic_string_view< char_type > format_str, basic_format_args< basic_format_context > ctx_args, internal::locale_ref loc=internal::locale_ref())
Definition: core.h:1104
basic_format_args< context > operator*() const
Definition: core.h:1369
#define FMT_ASSERT(condition, message)
Definition: core.h:168
FMT_CONSTEXPR iterator begin() const
Definition: core.h:389
#define FMT_BEGIN_NAMESPACE
Definition: core.h:153
#define const
Definition: zconf.h:214
const T & value
Definition: core.h:1346
basic_string_view< Char > to_string_view(basic_string_view< Char > s)
Definition: core.h:453
T * end() FMT_NOEXCEPT
Definition: core.h:245
#define FMT_OVERRIDE
Definition: core.h:88
custom_value< Context > custom
Definition: core.h:577
internal::error_handler error_handler()
Definition: core.h:1022
formatter< T, char_type > type
Definition: core.h:1085
value(double val)
Definition: core.h:584
GLenum GLuint GLsizei const GLchar * buf
Definition: glew.h:2580
string_value< signed char > sstring
Definition: core.h:575
FMT_CONSTEXPR basic_format_arg()
Definition: core.h:805
basic_parse_context< char_type > & parse_context()
Definition: core.h:1019
Context::char_type char_type
Definition: core.h:564
FMT_CONSTEXPR void remove_prefix(size_t n)
Definition: core.h:392
GLsizei const GLfloat * value
Definition: glew.h:1849
string_value< unsigned char > ustring
Definition: core.h:576
basic_parse_context< char > parse_context
Definition: core.h:925
GLdouble GLdouble t
Definition: glew.h:1398
FMT_CONSTEXPR init(const T &v)
Definition: core.h:633
FMT_CONSTEXPR internal::result_of< Visitor(int)>::type visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg)
Definition: core.h:828
const Char * value
Definition: core.h:550
unsigned long long ulong_long_value
Definition: core.h:570
long double long_double_value
Definition: core.h:572
basic_format_args(const format_arg *args, size_type count)
Definition: core.h:1267
type
Definition: core.h:528
FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT
Definition: core.h:894
void set(T *buf_data, std::size_t buf_capacity) FMT_NOEXCEPT
Definition: core.h:230
std::enable_if< internal::is_string< S >::value >::type print(std::basic_ostream< FMT_CHAR(S)> &os, const S &format_str, const Args &...args)
Definition: ostream.h:146
FMT_CONSTEXPR11 unsigned long long get_types()
Definition: core.h:1046