git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-11.0.2/include/fmt/compile.h

normal view · raw

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