Scippy

SoPlex

Sequential object-oriented simPlex

printf.h
Go to the documentation of this file.
1 // Formatting library for C++ - legacy printf implementation
2 //
3 // Copyright (c) 2012 - 2016, Victor Zverovich
4 // All rights reserved.
5 //
6 // For the license information refer to format.h.
7 
8 #ifndef FMT_PRINTF_H_
9 #define FMT_PRINTF_H_
10 
11 #include <algorithm> // std::max
12 #include <limits> // std::numeric_limits
13 
14 #include "ostream.h"
15 
17 namespace detail {
18 
19 // Checks if a value fits in int - used to avoid warnings about comparing
20 // signed and unsigned integers.
21 template <bool IsSigned> struct int_checker {
22  template <typename T> static bool fits_in_int(T value) {
23  unsigned max = max_value<int>();
24  return value <= max;
25  }
26  static bool fits_in_int(bool) { return true; }
27 };
28 
29 template <> struct int_checker<true> {
30  template <typename T> static bool fits_in_int(T value) {
31  return value >= (std::numeric_limits<int>::min)() &&
33  }
34  static bool fits_in_int(int) { return true; }
35 };
36 
38  public:
39  template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
40  int operator()(T value) {
42  FMT_THROW(format_error("number is too big"));
43  return (std::max)(static_cast<int>(value), 0);
44  }
45 
46  template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
47  int operator()(T) {
48  FMT_THROW(format_error("precision is not integer"));
49  return 0;
50  }
51 };
52 
53 // An argument visitor that returns true iff arg is a zero integer.
54 class is_zero_int {
55  public:
56  template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
57  bool operator()(T value) {
58  return value == 0;
59  }
60 
61  template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
62  bool operator()(T) {
63  return false;
64  }
65 };
66 
67 template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {};
68 
69 template <> struct make_unsigned_or_bool<bool> { using type = bool; };
70 
71 template <typename T, typename Context> class arg_converter {
72  private:
73  using char_type = typename Context::char_type;
74 
77 
78  public:
80  : arg_(arg), type_(type) {}
81 
82  void operator()(bool value) {
83  if (type_ != 's') operator()<bool>(value);
84  }
85 
86  template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)>
87  void operator()(U value) {
88  bool is_signed = type_ == 'd' || type_ == 'i';
89  using target_type = conditional_t<std::is_same<T, void>::value, U, T>;
90  if (const_check(sizeof(target_type) <= sizeof(int))) {
91  // Extra casts are used to silence warnings.
92  if (is_signed) {
93  arg_ = detail::make_arg<Context>(
94  static_cast<int>(static_cast<target_type>(value)));
95  } else {
96  using unsigned_type = typename make_unsigned_or_bool<target_type>::type;
97  arg_ = detail::make_arg<Context>(
98  static_cast<unsigned>(static_cast<unsigned_type>(value)));
99  }
100  } else {
101  if (is_signed) {
102  // glibc's printf doesn't sign extend arguments of smaller types:
103  // std::printf("%lld", -42); // prints "4294967254"
104  // but we don't have to do the same because it's a UB.
105  arg_ = detail::make_arg<Context>(static_cast<long long>(value));
106  } else {
107  arg_ = detail::make_arg<Context>(
108  static_cast<typename make_unsigned_or_bool<U>::type>(value));
109  }
110  }
111  }
112 
113  template <typename U, FMT_ENABLE_IF(!std::is_integral<U>::value)>
114  void operator()(U) {} // No conversion needed for non-integral types.
115 };
116 
117 // Converts an integer argument to T for printf, if T is an integral type.
118 // If T is void, the argument is converted to corresponding signed or unsigned
119 // type depending on the type specifier: 'd' and 'i' - signed, other -
120 // unsigned).
121 template <typename T, typename Context, typename Char>
124 }
125 
126 // Converts an integer argument to char for printf.
127 template <typename Context> class char_converter {
128  private:
130 
131  public:
132  explicit char_converter(basic_format_arg<Context>& arg) : arg_(arg) {}
133 
134  template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
135  void operator()(T value) {
136  arg_ = detail::make_arg<Context>(
137  static_cast<typename Context::char_type>(value));
138  }
139 
140  template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
141  void operator()(T) {} // No conversion needed for non-integral types.
142 };
143 
144 // An argument visitor that return a pointer to a C string if argument is a
145 // string or null otherwise.
146 template <typename Char> struct get_cstring {
147  template <typename T> const Char* operator()(T) { return nullptr; }
148  const Char* operator()(const Char* s) { return s; }
149 };
150 
151 // Checks if an argument is a valid printf width specifier and sets
152 // left alignment if it is negative.
153 template <typename Char> class printf_width_handler {
154  private:
156 
158 
159  public:
160  explicit printf_width_handler(format_specs& specs) : specs_(specs) {}
161 
162  template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
163  unsigned operator()(T value) {
164  auto width = static_cast<uint32_or_64_or_128_t<T>>(value);
165  if (detail::is_negative(value)) {
166  specs_.align = align::left;
167  width = 0 - width;
168  }
169  unsigned int_max = max_value<int>();
170  if (width > int_max) FMT_THROW(format_error("number is too big"));
171  return static_cast<unsigned>(width);
172  }
173 
174  template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
175  unsigned operator()(T) {
176  FMT_THROW(format_error("width is not integer"));
177  return 0;
178  }
179 };
180 
181 template <typename Char, typename Context>
184  Context(buffer_appender<Char>(buf), format, args).format();
185 }
186 } // namespace detail
187 
188 // For printing into memory_buffer.
189 template <typename Char, typename Context>
193  return detail::vprintf(buf, format, args);
194 }
195 using detail::vprintf;
196 
197 template <typename Char>
200 };
201 template <typename OutputIt, typename Char> class basic_printf_context;
202 
203 /**
204  \rst
205  The ``printf`` argument formatter.
206  \endrst
207  */
208 template <typename OutputIt, typename Char>
209 class printf_arg_formatter : public detail::arg_formatter_base<OutputIt, Char> {
210  public:
211  using iterator = OutputIt;
212 
213  private:
214  using char_type = Char;
217 
219 
220  void write_null_pointer(char) {
221  this->specs()->type = 0;
222  this->write("(nil)");
223  }
224 
225  void write_null_pointer(wchar_t) {
226  this->specs()->type = 0;
227  this->write(L"(nil)");
228  }
229 
230  public:
232 
233  /**
234  \rst
235  Constructs an argument formatter object.
236  *buffer* is a reference to the output buffer and *specs* contains format
237  specifier information for standard argument types.
238  \endrst
239  */
241  : base(iter, &specs, detail::locale_ref()), context_(ctx) {}
242 
243  template <typename T, FMT_ENABLE_IF(fmt::detail::is_integral<T>::value)>
244  iterator operator()(T value) {
245  // MSVC2013 fails to compile separate overloads for bool and char_type so
246  // use std::is_same instead.
247  if (std::is_same<T, bool>::value) {
248  format_specs& fmt_specs = *this->specs();
249  if (fmt_specs.type != 's') return base::operator()(value ? 1 : 0);
250  fmt_specs.type = 0;
251  this->write(value != 0);
252  } else if (std::is_same<T, char_type>::value) {
253  format_specs& fmt_specs = *this->specs();
254  if (fmt_specs.type && fmt_specs.type != 'c')
255  return (*this)(static_cast<int>(value));
256  fmt_specs.sign = sign::none;
257  fmt_specs.alt = false;
258  fmt_specs.fill[0] = ' '; // Ignore '0' flag for char types.
259  // align::numeric needs to be overwritten here since the '0' flag is
260  // ignored for non-numeric types
261  if (fmt_specs.align == align::none || fmt_specs.align == align::numeric)
262  fmt_specs.align = align::right;
263  return base::operator()(value);
264  } else {
265  return base::operator()(value);
266  }
267  return this->out();
268  }
269 
270  template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
271  iterator operator()(T value) {
272  return base::operator()(value);
273  }
274 
275  /** Formats a null-terminated C string. */
276  iterator operator()(const char* value) {
277  if (value)
278  base::operator()(value);
279  else if (this->specs()->type == 'p')
280  write_null_pointer(char_type());
281  else
282  this->write("(null)");
283  return this->out();
284  }
285 
286  /** Formats a null-terminated wide C string. */
287  iterator operator()(const wchar_t* value) {
288  if (value)
289  base::operator()(value);
290  else if (this->specs()->type == 'p')
291  write_null_pointer(char_type());
292  else
293  this->write(L"(null)");
294  return this->out();
295  }
296 
298  return base::operator()(value);
299  }
300 
301  iterator operator()(monostate value) { return base::operator()(value); }
302 
303  /** Formats a pointer. */
304  iterator operator()(const void* value) {
305  if (value) return base::operator()(value);
306  this->specs()->type = 0;
307  write_null_pointer(char_type());
308  return this->out();
309  }
310 
311  /** Formats an argument of a custom (user-defined) type. */
313  handle.format(context_.parse_context(), context_);
314  return this->out();
315  }
316 };
317 
318 template <typename T> struct printf_formatter {
319  printf_formatter() = delete;
320 
321  template <typename ParseContext>
322  auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
323  return ctx.begin();
324  }
325 
326  template <typename FormatContext>
327  auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) {
328  detail::format_value(detail::get_container(ctx.out()), value);
329  return ctx.out();
330  }
331 };
332 
333 /**
334  This template formats data and writes the output through an output iterator.
335  */
336 template <typename OutputIt, typename Char> class basic_printf_context {
337  public:
338  /** The character type for the output. */
339  using char_type = Char;
340  using iterator = OutputIt;
343  template <typename T> using formatter_type = printf_formatter<T>;
344 
345  private:
347 
348  OutputIt out_;
351 
352  static void parse_flags(format_specs& specs, const Char*& it,
353  const Char* end);
354 
355  // Returns the argument with specified index or, if arg_index is -1, the next
356  // argument.
357  format_arg get_arg(int arg_index = -1);
358 
359  // Parses argument index, flags and width and returns the argument index.
360  int parse_header(const Char*& it, const Char* end, format_specs& specs);
361 
362  public:
363  /**
364  \rst
365  Constructs a ``printf_context`` object. References to the arguments are
366  stored in the context object so make sure they have appropriate lifetimes.
367  \endrst
368  */
371  : out_(out), args_(args), parse_ctx_(format_str) {}
372 
373  OutputIt out() { return out_; }
374  void advance_to(OutputIt it) { out_ = it; }
375 
376  detail::locale_ref locale() { return {}; }
377 
378  format_arg arg(int id) const { return args_.get(id); }
379 
380  parse_context_type& parse_context() { return parse_ctx_; }
381 
382  FMT_CONSTEXPR void on_error(const char* message) {
383  parse_ctx_.on_error(message);
384  }
385 
386  /** Formats stored arguments and writes the output to the range. */
387  template <typename ArgFormatter = printf_arg_formatter<OutputIt, Char>>
388  OutputIt format();
389 };
390 
391 template <typename OutputIt, typename Char>
393  const Char*& it,
394  const Char* end) {
395  for (; it != end; ++it) {
396  switch (*it) {
397  case '-':
398  specs.align = align::left;
399  break;
400  case '+':
401  specs.sign = sign::plus;
402  break;
403  case '0':
404  specs.fill[0] = '0';
405  break;
406  case ' ':
407  if (specs.sign != sign::plus) {
408  specs.sign = sign::space;
409  }
410  break;
411  case '#':
412  specs.alt = true;
413  break;
414  default:
415  return;
416  }
417  }
418 }
419 
420 template <typename OutputIt, typename Char>
423  if (arg_index < 0)
424  arg_index = parse_ctx_.next_arg_id();
425  else
426  parse_ctx_.check_arg_id(--arg_index);
427  return detail::get_arg(*this, arg_index);
428 }
429 
430 template <typename OutputIt, typename Char>
432  const Char* end,
433  format_specs& specs) {
434  int arg_index = -1;
435  char_type c = *it;
436  if (c >= '0' && c <= '9') {
437  // Parse an argument index (if followed by '$') or a width possibly
438  // preceded with '0' flag(s).
440  int value = parse_nonnegative_int(it, end, eh);
441  if (it != end && *it == '$') { // value is an argument index
442  ++it;
443  arg_index = value;
444  } else {
445  if (c == '0') specs.fill[0] = '0';
446  if (value != 0) {
447  // Nonzero value means that we parsed width and don't need to
448  // parse it or flags again, so return now.
449  specs.width = value;
450  return arg_index;
451  }
452  }
453  }
454  parse_flags(specs, it, end);
455  // Parse width.
456  if (it != end) {
457  if (*it >= '0' && *it <= '9') {
459  specs.width = parse_nonnegative_int(it, end, eh);
460  } else if (*it == '*') {
461  ++it;
462  specs.width = static_cast<int>(visit_format_arg(
464  }
465  }
466  return arg_index;
467 }
468 
469 template <typename OutputIt, typename Char>
470 template <typename ArgFormatter>
472  auto out = this->out();
473  const Char* start = parse_ctx_.begin();
474  const Char* end = parse_ctx_.end();
475  auto it = start;
476  while (it != end) {
477  char_type c = *it++;
478  if (c != '%') continue;
479  if (it != end && *it == c) {
480  out = std::copy(start, it, out);
481  start = ++it;
482  continue;
483  }
484  out = std::copy(start, it - 1, out);
485 
486  format_specs specs;
487  specs.align = align::right;
488 
489  // Parse argument index, flags and width.
490  int arg_index = parse_header(it, end, specs);
491  if (arg_index == 0) on_error("argument not found");
492 
493  // Parse precision.
494  if (it != end && *it == '.') {
495  ++it;
496  c = it != end ? *it : 0;
497  if ('0' <= c && c <= '9') {
499  specs.precision = parse_nonnegative_int(it, end, eh);
500  } else if (c == '*') {
501  ++it;
502  specs.precision = static_cast<int>(
504  } else {
505  specs.precision = 0;
506  }
507  }
508 
509  format_arg arg = get_arg(arg_index);
510  // For d, i, o, u, x, and X conversion specifiers, if a precision is
511  // specified, the '0' flag is ignored
512  if (specs.precision >= 0 && arg.is_integral())
513  specs.fill[0] =
514  ' '; // Ignore '0' flag for non-numeric types or if '-' present.
515  if (specs.precision >= 0 && arg.type() == detail::type::cstring_type) {
516  auto str = visit_format_arg(detail::get_cstring<Char>(), arg);
517  auto str_end = str + specs.precision;
518  auto nul = std::find(str, str_end, Char());
519  arg = detail::make_arg<basic_printf_context>(basic_string_view<Char>(
520  str,
521  detail::to_unsigned(nul != str_end ? nul - str : specs.precision)));
522  }
523  if (specs.alt && visit_format_arg(detail::is_zero_int(), arg))
524  specs.alt = false;
525  if (specs.fill[0] == '0') {
526  if (arg.is_arithmetic() && specs.align != align::left)
527  specs.align = align::numeric;
528  else
529  specs.fill[0] = ' '; // Ignore '0' flag for non-numeric types or if '-'
530  // flag is also present.
531  }
532 
533  // Parse length and convert the argument to the required type.
534  c = it != end ? *it++ : 0;
535  char_type t = it != end ? *it : 0;
536  using detail::convert_arg;
537  switch (c) {
538  case 'h':
539  if (t == 'h') {
540  ++it;
541  t = it != end ? *it : 0;
542  convert_arg<signed char>(arg, t);
543  } else {
544  convert_arg<short>(arg, t);
545  }
546  break;
547  case 'l':
548  if (t == 'l') {
549  ++it;
550  t = it != end ? *it : 0;
551  convert_arg<long long>(arg, t);
552  } else {
553  convert_arg<long>(arg, t);
554  }
555  break;
556  case 'j':
557  convert_arg<intmax_t>(arg, t);
558  break;
559  case 'z':
560  convert_arg<size_t>(arg, t);
561  break;
562  case 't':
563  convert_arg<std::ptrdiff_t>(arg, t);
564  break;
565  case 'L':
566  // printf produces garbage when 'L' is omitted for long double, no
567  // need to do the same.
568  break;
569  default:
570  --it;
571  convert_arg<void>(arg, c);
572  }
573 
574  // Parse type.
575  if (it == end) FMT_THROW(format_error("invalid format string"));
576  specs.type = static_cast<char>(*it++);
577  if (arg.is_integral()) {
578  // Normalize type.
579  switch (specs.type) {
580  case 'i':
581  case 'u':
582  specs.type = 'd';
583  break;
584  case 'c':
586  arg);
587  break;
588  }
589  }
590 
591  start = it;
592 
593  // Format argument.
594  out = visit_format_arg(ArgFormatter(out, specs, *this), arg);
595  }
596  return std::copy(start, it, out);
597 }
598 
599 template <typename Char>
602 
605 
608 
609 /**
610  \rst
611  Constructs an `~fmt::format_arg_store` object that contains references to
612  arguments and can be implicitly converted to `~fmt::printf_args`.
613  \endrst
614  */
615 template <typename... Args>
617  const Args&... args) {
618  return {args...};
619 }
620 
621 /**
622  \rst
623  Constructs an `~fmt::format_arg_store` object that contains references to
624  arguments and can be implicitly converted to `~fmt::wprintf_args`.
625  \endrst
626  */
627 template <typename... Args>
629  const Args&... args) {
630  return {args...};
631 }
632 
633 template <typename S, typename Char = char_t<S>>
634 inline std::basic_string<Char> vsprintf(
635  const S& format,
638  vprintf(buffer, to_string_view(format), args);
639  return to_string(buffer);
640 }
641 
642 /**
643  \rst
644  Formats arguments and returns the result as a string.
645 
646  **Example**::
647 
648  std::string message = fmt::sprintf("The answer is %d", 42);
649  \endrst
650 */
651 template <typename S, typename... Args,
653 inline std::basic_string<Char> sprintf(const S& format, const Args&... args) {
654  using context = basic_printf_context_t<Char>;
655  return vsprintf(to_string_view(format), make_format_args<context>(args...));
656 }
657 
658 template <typename S, typename Char = char_t<S>>
659 inline int vfprintf(
660  std::FILE* f, const S& format,
663  vprintf(buffer, to_string_view(format), args);
664  size_t size = buffer.size();
665  return std::fwrite(buffer.data(), sizeof(Char), size, f) < size
666  ? -1
667  : static_cast<int>(size);
668 }
669 
670 /**
671  \rst
672  Prints formatted data to the file *f*.
673 
674  **Example**::
675 
676  fmt::fprintf(stderr, "Don't %s!", "panic");
677  \endrst
678  */
679 template <typename S, typename... Args,
681 inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
682  using context = basic_printf_context_t<Char>;
683  return vfprintf(f, to_string_view(format),
684  make_format_args<context>(args...));
685 }
686 
687 template <typename S, typename Char = char_t<S>>
688 inline int vprintf(
689  const S& format,
691  return vfprintf(stdout, to_string_view(format), args);
692 }
693 
694 /**
695  \rst
696  Prints formatted data to ``stdout``.
697 
698  **Example**::
699 
700  fmt::printf("Elapsed time: %.2f seconds", 1.23);
701  \endrst
702  */
703 template <typename S, typename... Args,
705 inline int printf(const S& format_str, const Args&... args) {
706  using context = basic_printf_context_t<char_t<S>>;
707  return vprintf(to_string_view(format_str),
708  make_format_args<context>(args...));
709 }
710 
711 template <typename S, typename Char = char_t<S>>
712 inline int vfprintf(
713  std::basic_ostream<Char>& os, const S& format,
716  vprintf(buffer, to_string_view(format), args);
717  detail::write_buffer(os, buffer);
718  return static_cast<int>(buffer.size());
719 }
720 
721 /** Formats arguments and writes the output to the range. */
722 template <typename ArgFormatter, typename Char,
723  typename Context =
725 typename ArgFormatter::iterator vprintf(
728  typename ArgFormatter::iterator iter(out);
729  Context(iter, format_str, args).template format<ArgFormatter>();
730  return iter;
731 }
732 
733 /**
734  \rst
735  Prints formatted data to the stream *os*.
736 
737  **Example**::
738 
739  fmt::fprintf(cerr, "Don't %s!", "panic");
740  \endrst
741  */
742 template <typename S, typename... Args, typename Char = char_t<S>>
743 inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
744  const Args&... args) {
745  using context = basic_printf_context_t<Char>;
746  return vfprintf(os, to_string_view(format_str),
747  make_format_args<context>(args...));
748 }
750 
751 #endif // FMT_PRINTF_H_
context_type & context_
Definition: printf.h:218
#define FMT_BEGIN_NAMESPACE
Definition: core.h:203
iterator operator()(monostate value)
Definition: printf.h:301
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition: color.h:560
void to_string_view(...)
typename Context::char_type char_type
Definition: printf.h:73
const Char * operator()(T)
Definition: printf.h:147
int parse_header(const Char *&it, const Char *end, format_specs &specs)
Definition: printf.h:431
printf_width_handler(format_specs &specs)
Definition: printf.h:160
basic_printf_context(OutputIt out, basic_string_view< char_type > format_str, basic_format_args< basic_printf_context > args)
Definition: printf.h:369
auto parse(ParseContext &ctx) -> decltype(ctx.begin())
Definition: printf.h:322
parse_context_type parse_ctx_
Definition: printf.h:350
std::basic_string< Char > sprintf(const S &format, const Args &... args)
Definition: printf.h:653
FMT_CONSTEXPR int parse_nonnegative_int(const Char *&begin, const Char *end, ErrorHandler &&eh)
Definition: format.h:2349
void format(typename Context::parse_context_type &parse_ctx, Context &ctx) const
Definition: core.h:1281
parse_context_type & parse_context()
Definition: printf.h:380
bool is_arithmetic() const
Definition: core.h:1299
int vfprintf(std::FILE *f, const S &format, basic_format_args< basic_printf_context_t< type_identity_t< Char >>> args)
Definition: printf.h:659
iterator operator()(basic_string_view< char_type > value)
Definition: printf.h:297
detail::locale_ref locale()
Definition: printf.h:376
OutputIt write(OutputIt out, basic_string_view< StrChar > s, const basic_format_specs< Char > &specs)
Definition: format.h:1568
basic_format_arg< Context > & arg_
Definition: printf.h:75
FMT_CONSTEXPR void on_error(const char *message)
Definition: core.h:614
void write_null_pointer(char)
Definition: printf.h:220
FMT_CONSTEXPR void on_error(const char *message)
Definition: printf.h:382
typename type_identity< T >::type type_identity_t
Definition: core.h:270
basic_format_arg< Context > & arg_
Definition: printf.h:129
int fprintf(std::FILE *f, const S &format, const Args &... args)
Definition: printf.h:681
bool is_integral() const
Definition: core.h:1298
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition: printf.h:182
static bool fits_in_int(T value)
Definition: printf.h:22
conditional_t< num_bits< T >()<=32 &&!FMT_REDUCE_INT_INSTANTIATIONS, uint32_t, conditional_t< num_bits< T >()<=64, uint64_t, uint128_t > > uint32_or_64_or_128_t
Definition: format.h:813
void advance_to(OutputIt it)
Definition: printf.h:374
#define FMT_THROW(x)
Definition: format.h:113
OutputIt iterator
Definition: printf.h:211
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:325
void format_value(buffer< Char > &buf, const T &value, locale_ref loc=locale_ref())
Definition: ostream.h:107
type
Definition: core.h:977
iterator operator()(const void *value)
Definition: printf.h:304
static bool fits_in_int(T value)
Definition: printf.h:30
OutputIt format()
Definition: printf.h:471
format_specs & specs_
Definition: printf.h:157
basic_format_args< basic_printf_context > args_
Definition: printf.h:349
#define FMT_END_NAMESPACE
Definition: core.h:198
format_arg get_arg(int arg_index=-1)
Definition: printf.h:422
const Char * operator()(const Char *s)
Definition: printf.h:148
format_arg_store< printf_context, Args... > make_printf_args(const Args &... args)
Definition: printf.h:616
std::basic_string< Char > vsprintf(const S &format, basic_format_args< basic_printf_context_t< type_identity_t< Char >>> args)
Definition: printf.h:634
Definition: chrono.h:284
FMT_DEPRECATED void printf(detail::buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition: printf.h:190
std::string to_string(const T &value)
Definition: format.h:3730
detail::type type() const
Definition: core.h:1296
OutputIterator copy(const RangeT &range, OutputIterator out)
Definition: ranges.h:60
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:259
auto format(const T &value, FormatContext &ctx) -> decltype(ctx.out())
Definition: printf.h:327
static bool fits_in_int(bool)
Definition: printf.h:26
FMT_CONSTEXPR bool is_negative(T value)
Definition: format.h:792
#define FMT_ENABLE_IF(...)
Definition: core.h:277
typename detail::char_t_impl< S >::type char_t
Definition: core.h:540
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_t >::value > is_signed
Definition: format.h:787
basic_format_specs< char > format_specs
Definition: format.h:1203
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:261
void convert_arg(basic_format_arg< Context > &arg, Char type)
Definition: printf.h:122
#define FMT_DEPRECATED
Definition: core.h:161
basic_printf_context_t< wchar_t > wprintf_context
Definition: printf.h:604
void write_null_pointer(wchar_t)
Definition: printf.h:225
size_t size() const FMT_NOEXCEPT
Definition: core.h:706
format_arg get(int id) const
Definition: core.h:1897
T * data() FMT_NOEXCEPT
Definition: core.h:712
static bool fits_in_int(int)
Definition: printf.h:34
OutputIt iterator
Definition: printf.h:340
static void parse_flags(format_specs &specs, const Char *&it, const Char *end)
Definition: printf.h:392
OutputIt out()
Definition: printf.h:373
typename base::format_specs format_specs
Definition: printf.h:231
FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition: core.h:1310
detail::fill_t< Char > fill
Definition: format.h:1192
basic_printf_context_t< char > printf_context
Definition: printf.h:603
arg_converter(basic_format_arg< Context > &arg, char_type type)
Definition: printf.h:79
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
Definition: core.h:1640
char_converter(basic_format_arg< Context > &arg)
Definition: printf.h:132
constexpr T const_check(T value)
Definition: core.h:282
iterator operator()(const char *value)
Definition: printf.h:276
Container & get_container(std::back_insert_iterator< Container > it)
Definition: core.h:650
FMT_CONSTEXPR Context::format_arg get_arg(Context &ctx, ID id)
Definition: format.h:2559
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2929
iterator operator()(typename basic_format_arg< context_type >::handle handle)
Definition: printf.h:312
printf_arg_formatter(iterator iter, format_specs &specs, context_type &ctx)
Definition: printf.h:240
#define FMT_CONSTEXPR
Definition: core.h:98
char_type type_
Definition: printf.h:76
format_arg_store< wprintf_context, Args... > make_wprintf_args(const Args &... args)
Definition: printf.h:628
void operator()(bool value)
Definition: printf.h:82
format_arg arg(int id) const
Definition: printf.h:378
void write_buffer(std::basic_ostream< Char > &os, buffer< Char > &buf)
Definition: ostream.h:93
iterator operator()(const wchar_t *value)
Definition: printf.h:287