| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
1 |
// Formatting library for C++ - range and tuple support |
| 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_RANGES_H_ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
9 |
#define FMT_RANGES_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 <initializer_list> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
13 |
# include <iterator> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
14 |
# include <string> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
15 |
# include <tuple> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
16 |
# include <type_traits> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
17 |
# include <utility> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
18 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
19 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
20 |
#include "format.h" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
21 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
22 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
23 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
24 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
25 |
enum class range_format { disabled, map, set, sequence, string, debug_string }; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
26 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
27 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
28 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
29 |
template <typename T> class is_map { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
30 |
template <typename U> static auto check(U*) -> typename U::mapped_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
31 |
template <typename> static void check(...); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
32 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
33 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
34 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
35 |
!std::is_void<decltype(check<T>(nullptr))>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
36 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
37 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
38 |
template <typename T> class is_set { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
39 |
template <typename U> static auto check(U*) -> typename U::key_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
40 |
template <typename> static void check(...); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
41 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
42 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
43 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
44 |
!std::is_void<decltype(check<T>(nullptr))>::value && !is_map<T>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
45 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
46 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
47 |
template <typename... Ts> struct conditional_helper {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
48 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
49 |
template <typename T, typename _ = void> struct is_range_ : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
50 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
51 |
#if !FMT_MSC_VERSION || FMT_MSC_VERSION > 1800 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
52 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
53 |
# define FMT_DECLTYPE_RETURN(val) \ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
54 |
->decltype(val) { return val; } \ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
55 |
static_assert( \ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
56 |
true, "") // This makes it so that a semicolon is required after the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
57 |
// macro, which helps clang-format handle the formatting. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
58 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
59 |
// C array overload |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
60 |
template <typename T, std::size_t N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
61 |
auto range_begin(const T (&arr)[N]) -> const T* { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
62 |
return arr; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
63 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
64 |
template <typename T, std::size_t N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
65 |
auto range_end(const T (&arr)[N]) -> const T* { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
66 |
return arr + N; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
67 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
68 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
69 |
template <typename T, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
70 |
struct has_member_fn_begin_end_t : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
71 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
72 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
73 |
struct has_member_fn_begin_end_t<T, void_t<decltype(*std::declval<T>().begin()), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
74 |
decltype(std::declval<T>().end())>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
75 |
: std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
76 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
77 |
// Member function overloads. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
78 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
79 |
auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).begin()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
80 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
81 |
auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).end()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
82 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
83 |
// ADL overloads. Only participate in overload resolution if member functions |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
84 |
// are not found. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
85 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
86 |
auto range_begin(T&& rng) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
87 |
-> enable_if_t<!has_member_fn_begin_end_t<T&&>::value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
88 |
decltype(begin(static_cast<T&&>(rng)))> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
89 |
return begin(static_cast<T&&>(rng)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
90 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
91 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
92 |
auto range_end(T&& rng) -> enable_if_t<!has_member_fn_begin_end_t<T&&>::value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
93 |
decltype(end(static_cast<T&&>(rng)))> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
94 |
return end(static_cast<T&&>(rng)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
95 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
96 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
97 |
template <typename T, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
98 |
struct has_const_begin_end : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
99 |
template <typename T, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
100 |
struct has_mutable_begin_end : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
101 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
102 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
103 |
struct has_const_begin_end< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
104 |
T, void_t<decltype(*detail::range_begin( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
105 |
std::declval<const remove_cvref_t<T>&>())), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
106 |
decltype(detail::range_end( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
107 |
std::declval<const remove_cvref_t<T>&>()))>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
108 |
: std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
109 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
110 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
111 |
struct has_mutable_begin_end< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
112 |
T, void_t<decltype(*detail::range_begin(std::declval<T&>())), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
113 |
decltype(detail::range_end(std::declval<T&>())), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
114 |
// the extra int here is because older versions of MSVC don't |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
115 |
// SFINAE properly unless there are distinct types |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
116 |
int>> : std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
117 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
118 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
119 |
struct is_range_<T, void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
120 |
: std::integral_constant<bool, (has_const_begin_end<T>::value || |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
121 |
has_mutable_begin_end<T>::value)> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
122 |
# undef FMT_DECLTYPE_RETURN |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
123 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
124 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
125 |
// tuple_size and tuple_element check. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
126 |
template <typename T> class is_tuple_like_ { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
127 |
template <typename U> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
128 |
static auto check(U* p) -> decltype(std::tuple_size<U>::value, int()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
129 |
template <typename> static void check(...); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
130 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
131 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
132 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
133 |
!std::is_void<decltype(check<T>(nullptr))>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
134 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
135 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
136 |
// Check for integer_sequence |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
137 |
#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VERSION >= 1900 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
138 |
template <typename T, T... N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
139 |
using integer_sequence = std::integer_sequence<T, N...>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
140 |
template <size_t... N> using index_sequence = std::index_sequence<N...>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
141 |
template <size_t N> using make_index_sequence = std::make_index_sequence<N>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
142 |
#else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
143 |
template <typename T, T... N> struct integer_sequence { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
144 |
using value_type = T; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
145 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
146 |
static FMT_CONSTEXPR auto size() -> size_t { return sizeof...(N); } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
147 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
148 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
149 |
template <size_t... N> using index_sequence = integer_sequence<size_t, N...>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
150 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
151 |
template <typename T, size_t N, T... Ns> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
152 |
struct make_integer_sequence : make_integer_sequence<T, N - 1, N - 1, Ns...> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
153 |
template <typename T, T... Ns> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
154 |
struct make_integer_sequence<T, 0, Ns...> : integer_sequence<T, Ns...> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
155 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
156 |
template <size_t N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
157 |
using make_index_sequence = make_integer_sequence<size_t, N>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
158 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
159 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
160 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
161 |
using tuple_index_sequence = make_index_sequence<std::tuple_size<T>::value>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
162 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
163 |
template <typename T, typename C, bool = is_tuple_like_<T>::value> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
164 |
class is_tuple_formattable_ { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
165 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
166 |
static constexpr const bool value = false; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
167 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
168 |
template <typename T, typename C> class is_tuple_formattable_<T, C, true> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
169 |
template <size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
170 |
static auto all_true(index_sequence<Is...>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
171 |
integer_sequence<bool, (Is >= 0)...>) -> std::true_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
172 |
static auto all_true(...) -> std::false_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
173 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
174 |
template <size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
175 |
static auto check(index_sequence<Is...>) -> decltype(all_true( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
176 |
index_sequence<Is...>{}, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
177 |
integer_sequence<bool, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
178 |
(is_formattable<typename std::tuple_element<Is, T>::type, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
179 |
C>::value)...>{})); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
180 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
181 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
182 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
183 |
decltype(check(tuple_index_sequence<T>{}))::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
184 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
185 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
186 |
template <typename Tuple, typename F, size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
187 |
FMT_CONSTEXPR void for_each(index_sequence<Is...>, Tuple&& t, F&& f) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
188 |
using std::get; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
189 |
// Using a free function get<Is>(Tuple) now. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
190 |
const int unused[] = {0, ((void)f(get<Is>(t)), 0)...}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
191 |
ignore_unused(unused); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
192 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
193 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
194 |
template <typename Tuple, typename F> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
195 |
FMT_CONSTEXPR void for_each(Tuple&& t, F&& f) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
196 |
for_each(tuple_index_sequence<remove_cvref_t<Tuple>>(), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
197 |
std::forward<Tuple>(t), std::forward<F>(f)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
198 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
199 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
200 |
template <typename Tuple1, typename Tuple2, typename F, size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
201 |
void for_each2(index_sequence<Is...>, Tuple1&& t1, Tuple2&& t2, F&& f) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
202 |
using std::get; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
203 |
const int unused[] = {0, ((void)f(get<Is>(t1), get<Is>(t2)), 0)...}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
204 |
ignore_unused(unused); |
| 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 Tuple1, typename Tuple2, typename F> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
208 |
void for_each2(Tuple1&& t1, Tuple2&& t2, F&& f) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
209 |
for_each2(tuple_index_sequence<remove_cvref_t<Tuple1>>(), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
210 |
std::forward<Tuple1>(t1), std::forward<Tuple2>(t2), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
211 |
std::forward<F>(f)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
212 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
213 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
214 |
namespace tuple { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
215 |
// Workaround a bug in MSVC 2019 (v140). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
216 |
template <typename Char, typename... T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
217 |
using result_t = std::tuple<formatter<remove_cvref_t<T>, Char>...>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
218 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
219 |
using std::get; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
220 |
template <typename Tuple, typename Char, std::size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
221 |
auto get_formatters(index_sequence<Is...>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
222 |
-> result_t<Char, decltype(get<Is>(std::declval<Tuple>()))...>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
223 |
} // namespace tuple |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
224 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
225 |
#if FMT_MSC_VERSION && FMT_MSC_VERSION < 1920 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
226 |
// Older MSVC doesn't get the reference type correctly for arrays. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
227 |
template <typename R> struct range_reference_type_impl { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
228 |
using type = decltype(*detail::range_begin(std::declval<R&>())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
229 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
230 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
231 |
template <typename T, std::size_t N> struct range_reference_type_impl<T[N]> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
232 |
using type = T&; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
233 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
234 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
235 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
236 |
using range_reference_type = typename range_reference_type_impl<T>::type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
237 |
#else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
238 |
template <typename Range> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
239 |
using range_reference_type = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
240 |
decltype(*detail::range_begin(std::declval<Range&>())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
241 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
242 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
243 |
// We don't use the Range's value_type for anything, but we do need the Range's |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
244 |
// reference type, with cv-ref stripped. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
245 |
template <typename Range> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
246 |
using uncvref_type = remove_cvref_t<range_reference_type<Range>>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
247 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
248 |
template <typename Formatter> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
249 |
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
250 |
-> decltype(f.set_debug_format(set)) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
251 |
f.set_debug_format(set); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
252 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
253 |
template <typename Formatter> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
254 |
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
255 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
256 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
257 |
struct range_format_kind_ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
258 |
: std::integral_constant<range_format, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
259 |
std::is_same<uncvref_type<T>, T>::value |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
260 |
? range_format::disabled |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
261 |
: is_map<T>::value ? range_format::map |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
262 |
: is_set<T>::value ? range_format::set |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
263 |
: range_format::sequence> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
264 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
265 |
template <range_format K> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
266 |
using range_format_constant = std::integral_constant<range_format, K>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
267 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
268 |
// These are not generic lambdas for compatibility with C++11. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
269 |
template <typename ParseContext> struct parse_empty_specs { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
270 |
template <typename Formatter> FMT_CONSTEXPR void operator()(Formatter& f) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
271 |
f.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
272 |
detail::maybe_set_debug_format(f, true); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
273 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
274 |
ParseContext& ctx; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
275 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
276 |
template <typename FormatContext> struct format_tuple_element { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
277 |
using char_type = typename FormatContext::char_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
278 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
279 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
280 |
void operator()(const formatter<T, char_type>& f, const T& v) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
281 |
if (i > 0) ctx.advance_to(detail::copy<char_type>(separator, ctx.out())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
282 |
ctx.advance_to(f.format(v, ctx)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
283 |
++i; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
284 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
285 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
286 |
int i; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
287 |
FormatContext& ctx; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
288 |
basic_string_view<char_type> separator; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
289 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
290 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
291 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
292 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
293 |
template <typename T> struct is_tuple_like { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
294 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
295 |
detail::is_tuple_like_<T>::value && !detail::is_range_<T>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
296 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
297 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
298 |
template <typename T, typename C> struct is_tuple_formattable { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
299 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
300 |
detail::is_tuple_formattable_<T, C>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
301 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
302 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
303 |
template <typename Tuple, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
304 |
struct formatter<Tuple, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
305 |
enable_if_t<fmt::is_tuple_like<Tuple>::value && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
306 |
fmt::is_tuple_formattable<Tuple, Char>::value>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
307 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
308 |
decltype(detail::tuple::get_formatters<Tuple, Char>( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
309 |
detail::tuple_index_sequence<Tuple>())) formatters_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
310 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
311 |
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
312 |
basic_string_view<Char> opening_bracket_ = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
313 |
detail::string_literal<Char, '('>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
314 |
basic_string_view<Char> closing_bracket_ = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
315 |
detail::string_literal<Char, ')'>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
316 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
317 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
318 |
FMT_CONSTEXPR formatter() {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
319 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
320 |
FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
321 |
separator_ = sep; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
322 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
323 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
324 |
FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
325 |
basic_string_view<Char> close) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
326 |
opening_bracket_ = open; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
327 |
closing_bracket_ = close; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
328 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
329 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
330 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
331 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
332 |
auto it = ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
333 |
if (it != ctx.end() && *it != '}') report_error("invalid format specifier"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
334 |
detail::for_each(formatters_, detail::parse_empty_specs<ParseContext>{ctx}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
335 |
return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
336 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
337 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
338 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
339 |
auto format(const Tuple& value, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
340 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
341 |
ctx.advance_to(detail::copy<Char>(opening_bracket_, ctx.out())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
342 |
detail::for_each2( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
343 |
formatters_, value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
344 |
detail::format_tuple_element<FormatContext>{0, ctx, separator_}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
345 |
return detail::copy<Char>(closing_bracket_, ctx.out()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
346 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
347 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
348 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
349 |
template <typename T, typename Char> struct is_range { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
350 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
351 |
detail::is_range_<T>::value && !detail::has_to_string_view<T>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
352 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
353 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
354 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
355 |
template <typename Context> struct range_mapper { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
356 |
using mapper = arg_mapper<Context>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
357 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
358 |
template <typename T, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
359 |
FMT_ENABLE_IF(has_formatter<remove_cvref_t<T>, Context>::value)> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
360 |
static auto map(T&& value) -> T&& { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
361 |
return static_cast<T&&>(value); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
362 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
363 |
template <typename T, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
364 |
FMT_ENABLE_IF(!has_formatter<remove_cvref_t<T>, Context>::value)> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
365 |
static auto map(T&& value) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
366 |
-> decltype(mapper().map(static_cast<T&&>(value))) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
367 |
return mapper().map(static_cast<T&&>(value)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
368 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
369 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
370 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
371 |
template <typename Char, typename Element> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
372 |
using range_formatter_type = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
373 |
formatter<remove_cvref_t<decltype(range_mapper<buffered_context<Char>>{} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
374 |
.map(std::declval<Element>()))>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
375 |
Char>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
376 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
377 |
template <typename R> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
378 |
using maybe_const_range = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
379 |
conditional_t<has_const_begin_end<R>::value, const R, R>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
380 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
381 |
// Workaround a bug in MSVC 2015 and earlier. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
382 |
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
383 |
template <typename R, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
384 |
struct is_formattable_delayed |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
385 |
: is_formattable<uncvref_type<maybe_const_range<R>>, Char> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
386 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
387 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
388 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
389 |
template <typename...> struct conjunction : std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
390 |
template <typename P> struct conjunction<P> : P {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
391 |
template <typename P1, typename... Pn> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
392 |
struct conjunction<P1, Pn...> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
393 |
: conditional_t<bool(P1::value), conjunction<Pn...>, P1> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
394 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
395 |
template <typename T, typename Char, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
396 |
struct range_formatter; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
397 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
398 |
template <typename T, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
399 |
struct range_formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
400 |
T, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
401 |
enable_if_t<conjunction<std::is_same<T, remove_cvref_t<T>>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
402 |
is_formattable<T, Char>>::value>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
403 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
404 |
detail::range_formatter_type<Char, T> underlying_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
405 |
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
406 |
basic_string_view<Char> opening_bracket_ = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
407 |
detail::string_literal<Char, '['>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
408 |
basic_string_view<Char> closing_bracket_ = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
409 |
detail::string_literal<Char, ']'>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
410 |
bool is_debug = false; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
411 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
412 |
template <typename Output, typename It, typename Sentinel, typename U = T, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
413 |
FMT_ENABLE_IF(std::is_same<U, Char>::value)> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
414 |
auto write_debug_string(Output& out, It it, Sentinel end) const -> Output { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
415 |
auto buf = basic_memory_buffer<Char>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
416 |
for (; it != end; ++it) buf.push_back(*it); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
417 |
auto specs = format_specs(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
418 |
specs.type = presentation_type::debug; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
419 |
return detail::write<Char>( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
420 |
out, basic_string_view<Char>(buf.data(), buf.size()), specs); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
421 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
422 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
423 |
template <typename Output, typename It, typename Sentinel, typename U = T, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
424 |
FMT_ENABLE_IF(!std::is_same<U, Char>::value)> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
425 |
auto write_debug_string(Output& out, It, Sentinel) const -> Output { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
426 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
427 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
428 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
429 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
430 |
FMT_CONSTEXPR range_formatter() {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
431 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
432 |
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
433 |
return underlying_; |
| 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 |
FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
437 |
separator_ = sep; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
438 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
439 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
440 |
FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
441 |
basic_string_view<Char> close) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
442 |
opening_bracket_ = open; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
443 |
closing_bracket_ = close; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
444 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
445 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
446 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
447 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
448 |
auto it = ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
449 |
auto end = ctx.end(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
450 |
detail::maybe_set_debug_format(underlying_, true); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
451 |
if (it == end) return underlying_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
452 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
453 |
switch (detail::to_ascii(*it)) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
454 |
case 'n': |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
455 |
set_brackets({}, {}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
456 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
457 |
break; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
458 |
case '?': |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
459 |
is_debug = true; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
460 |
set_brackets({}, {}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
461 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
462 |
if (it == end || *it != 's') report_error("invalid format specifier"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
463 |
FMT_FALLTHROUGH; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
464 |
case 's': |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
465 |
if (!std::is_same<T, Char>::value) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
466 |
report_error("invalid format specifier"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
467 |
if (!is_debug) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
468 |
set_brackets(detail::string_literal<Char, '"'>{}, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
469 |
detail::string_literal<Char, '"'>{}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
470 |
set_separator({}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
471 |
detail::maybe_set_debug_format(underlying_, false); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
472 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
473 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
474 |
return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
475 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
476 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
477 |
if (it != end && *it != '}') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
478 |
if (*it != ':') report_error("invalid format specifier"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
479 |
detail::maybe_set_debug_format(underlying_, false); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
480 |
++it; |
| 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 |
ctx.advance_to(it); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
484 |
return underlying_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
485 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
486 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
487 |
template <typename R, typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
488 |
auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
489 |
auto mapper = detail::range_mapper<buffered_context<Char>>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
490 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
491 |
auto it = detail::range_begin(range); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
492 |
auto end = detail::range_end(range); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
493 |
if (is_debug) return write_debug_string(out, std::move(it), end); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
494 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
495 |
out = detail::copy<Char>(opening_bracket_, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
496 |
int i = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
497 |
for (; it != end; ++it) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
498 |
if (i > 0) out = detail::copy<Char>(separator_, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
499 |
ctx.advance_to(out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
500 |
auto&& item = *it; // Need an lvalue |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
501 |
out = underlying_.format(mapper.map(item), ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
502 |
++i; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
503 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
504 |
out = detail::copy<Char>(closing_bracket_, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
505 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
506 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
507 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
508 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
509 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
510 |
template <typename T, typename Char, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
511 |
struct range_format_kind |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
512 |
: conditional_t< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
513 |
is_range<T, Char>::value, detail::range_format_kind_<T>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
514 |
std::integral_constant<range_format, range_format::disabled>> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
515 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
516 |
template <typename R, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
517 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
518 |
R, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
519 |
enable_if_t<conjunction< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
520 |
bool_constant< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
521 |
range_format_kind<R, Char>::value != range_format::disabled && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
522 |
range_format_kind<R, Char>::value != range_format::map && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
523 |
range_format_kind<R, Char>::value != range_format::string && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
524 |
range_format_kind<R, Char>::value != range_format::debug_string> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
525 |
// Workaround a bug in MSVC 2015 and earlier. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
526 |
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
527 |
, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
528 |
detail::is_formattable_delayed<R, Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
529 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
530 |
>::value>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
531 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
532 |
using range_type = detail::maybe_const_range<R>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
533 |
range_formatter<detail::uncvref_type<range_type>, Char> range_formatter_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
534 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
535 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
536 |
using nonlocking = void; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
537 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
538 |
FMT_CONSTEXPR formatter() { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
539 |
if (detail::const_check(range_format_kind<R, Char>::value != |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
540 |
range_format::set)) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
541 |
return; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
542 |
range_formatter_.set_brackets(detail::string_literal<Char, '{'>{}, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
543 |
detail::string_literal<Char, '}'>{}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
544 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
545 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
546 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
547 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
548 |
return range_formatter_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
549 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
550 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
551 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
552 |
auto format(range_type& range, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
553 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
554 |
return range_formatter_.format(range, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
555 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
556 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
557 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
558 |
// A map formatter. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
559 |
template <typename R, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
560 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
561 |
R, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
562 |
enable_if_t<range_format_kind<R, Char>::value == range_format::map>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
563 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
564 |
using map_type = detail::maybe_const_range<R>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
565 |
using element_type = detail::uncvref_type<map_type>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
566 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
567 |
decltype(detail::tuple::get_formatters<element_type, Char>( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
568 |
detail::tuple_index_sequence<element_type>())) formatters_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
569 |
bool no_delimiters_ = false; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
570 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
571 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
572 |
FMT_CONSTEXPR formatter() {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
573 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
574 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
575 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
576 |
auto it = ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
577 |
auto end = ctx.end(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
578 |
if (it != end) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
579 |
if (detail::to_ascii(*it) == 'n') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
580 |
no_delimiters_ = true; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
581 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
582 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
583 |
if (it != end && *it != '}') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
584 |
if (*it != ':') report_error("invalid format specifier"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
585 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
586 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
587 |
ctx.advance_to(it); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
588 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
589 |
detail::for_each(formatters_, detail::parse_empty_specs<ParseContext>{ctx}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
590 |
return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
591 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
592 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
593 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
594 |
auto format(map_type& map, FormatContext& ctx) const -> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
595 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
596 |
basic_string_view<Char> open = detail::string_literal<Char, '{'>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
597 |
if (!no_delimiters_) out = detail::copy<Char>(open, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
598 |
int i = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
599 |
auto mapper = detail::range_mapper<buffered_context<Char>>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
600 |
basic_string_view<Char> sep = detail::string_literal<Char, ',', ' '>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
601 |
for (auto&& value : map) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
602 |
if (i > 0) out = detail::copy<Char>(sep, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
603 |
ctx.advance_to(out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
604 |
detail::for_each2(formatters_, mapper.map(value), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
605 |
detail::format_tuple_element<FormatContext>{ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
606 |
0, ctx, detail::string_literal<Char, ':', ' '>{}}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
607 |
++i; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
608 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
609 |
basic_string_view<Char> close = detail::string_literal<Char, '}'>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
610 |
if (!no_delimiters_) out = detail::copy<Char>(close, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
611 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
612 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
613 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
614 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
615 |
// A (debug_)string formatter. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
616 |
template <typename R, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
617 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
618 |
R, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
619 |
enable_if_t<range_format_kind<R, Char>::value == range_format::string || |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
620 |
range_format_kind<R, Char>::value == |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
621 |
range_format::debug_string>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
622 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
623 |
using range_type = detail::maybe_const_range<R>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
624 |
using string_type = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
625 |
conditional_t<std::is_constructible< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
626 |
detail::std_string_view<Char>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
627 |
decltype(detail::range_begin(std::declval<R>())), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
628 |
decltype(detail::range_end(std::declval<R>()))>::value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
629 |
detail::std_string_view<Char>, std::basic_string<Char>>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
630 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
631 |
formatter<string_type, Char> underlying_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
632 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
633 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
634 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
635 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
636 |
return underlying_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
637 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
638 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
639 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
640 |
auto format(range_type& range, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
641 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
642 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
643 |
if (detail::const_check(range_format_kind<R, Char>::value == |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
644 |
range_format::debug_string)) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
645 |
*out++ = '"'; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
646 |
out = underlying_.format( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
647 |
string_type{detail::range_begin(range), detail::range_end(range)}, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
648 |
if (detail::const_check(range_format_kind<R, Char>::value == |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
649 |
range_format::debug_string)) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
650 |
*out++ = '"'; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
651 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
652 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
653 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
654 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
655 |
template <typename It, typename Sentinel, typename Char = char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
656 |
struct join_view : detail::view { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
657 |
It begin; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
658 |
Sentinel end; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
659 |
basic_string_view<Char> sep; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
660 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
661 |
join_view(It b, Sentinel e, basic_string_view<Char> s) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
662 |
: begin(std::move(b)), end(e), sep(s) {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
663 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
664 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
665 |
template <typename It, typename Sentinel, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
666 |
struct formatter<join_view<It, Sentinel, Char>, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
667 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
668 |
using value_type = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
669 |
#ifdef __cpp_lib_ranges |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
670 |
std::iter_value_t<It>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
671 |
#else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
672 |
typename std::iterator_traits<It>::value_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
673 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
674 |
formatter<remove_cvref_t<value_type>, Char> value_formatter_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
675 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
676 |
using view_ref = conditional_t<std::is_copy_constructible<It>::value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
677 |
const join_view<It, Sentinel, Char>&, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
678 |
join_view<It, Sentinel, Char>&&>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
679 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
680 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
681 |
using nonlocking = void; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
682 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
683 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
684 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> const Char* { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
685 |
return value_formatter_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
686 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
687 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
688 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
689 |
auto format(view_ref& value, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
690 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
691 |
auto it = std::forward<view_ref>(value).begin; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
692 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
693 |
if (it == value.end) return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
694 |
out = value_formatter_.format(*it, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
695 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
696 |
while (it != value.end) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
697 |
out = detail::copy<Char>(value.sep.begin(), value.sep.end(), out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
698 |
ctx.advance_to(out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
699 |
out = value_formatter_.format(*it, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
700 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
701 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
702 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
703 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
704 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
705 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
706 |
/// Returns a view that formats the iterator range `[begin, end)` with elements |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
707 |
/// separated by `sep`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
708 |
template <typename It, typename Sentinel> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
709 |
auto join(It begin, Sentinel end, string_view sep) -> join_view<It, Sentinel> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
710 |
return {std::move(begin), end, sep}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
711 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
712 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
713 |
/** |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
714 |
* Returns a view that formats `range` with elements separated by `sep`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
715 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
716 |
* **Example**: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
717 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
718 |
* auto v = std::vector<int>{1, 2, 3}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
719 |
* fmt::print("{}", fmt::join(v, ", ")); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
720 |
* // Output: 1, 2, 3 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
721 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
722 |
* `fmt::join` applies passed format specifiers to the range elements: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
723 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
724 |
* fmt::print("{:02}", fmt::join(v, ", ")); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
725 |
* // Output: 01, 02, 03 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
726 |
*/ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
727 |
template <typename Range> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
728 |
auto join(Range&& r, string_view sep) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
729 |
-> join_view<decltype(detail::range_begin(r)), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
730 |
decltype(detail::range_end(r))> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
731 |
return {detail::range_begin(r), detail::range_end(r), sep}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
732 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
733 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
734 |
template <typename Char, typename... T> struct tuple_join_view : detail::view { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
735 |
const std::tuple<T...>& tuple; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
736 |
basic_string_view<Char> sep; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
737 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
738 |
tuple_join_view(const std::tuple<T...>& t, basic_string_view<Char> s) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
739 |
: tuple(t), sep{s} {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
740 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
741 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
742 |
// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
743 |
// support in tuple_join. It is disabled by default because of issues with |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
744 |
// the dynamic width and precision. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
745 |
#ifndef FMT_TUPLE_JOIN_SPECIFIERS |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
746 |
# define FMT_TUPLE_JOIN_SPECIFIERS 0 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
747 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
748 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
749 |
template <typename Char, typename... T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
750 |
struct formatter<tuple_join_view<Char, T...>, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
751 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
752 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
753 |
return do_parse(ctx, std::integral_constant<size_t, sizeof...(T)>()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
754 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
755 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
756 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
757 |
auto format(const tuple_join_view<Char, T...>& value, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
758 |
FormatContext& ctx) const -> typename FormatContext::iterator { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
759 |
return do_format(value, ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
760 |
std::integral_constant<size_t, sizeof...(T)>()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
761 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
762 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
763 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
764 |
std::tuple<formatter<typename std::decay<T>::type, Char>...> formatters_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
765 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
766 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
767 |
FMT_CONSTEXPR auto do_parse(ParseContext& ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
768 |
std::integral_constant<size_t, 0>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
769 |
-> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
770 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
771 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
772 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
773 |
template <typename ParseContext, size_t N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
774 |
FMT_CONSTEXPR auto do_parse(ParseContext& ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
775 |
std::integral_constant<size_t, N>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
776 |
-> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
777 |
auto end = ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
778 |
#if FMT_TUPLE_JOIN_SPECIFIERS |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
779 |
end = std::get<sizeof...(T) - N>(formatters_).parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
780 |
if (N > 1) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
781 |
auto end1 = do_parse(ctx, std::integral_constant<size_t, N - 1>()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
782 |
if (end != end1) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
783 |
report_error("incompatible format specs for tuple elements"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
784 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
785 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
786 |
return end; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
787 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
788 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
789 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
790 |
auto do_format(const tuple_join_view<Char, T...>&, FormatContext& ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
791 |
std::integral_constant<size_t, 0>) const -> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
792 |
typename FormatContext::iterator { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
793 |
return ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
794 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
795 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
796 |
template <typename FormatContext, size_t N> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
797 |
auto do_format(const tuple_join_view<Char, T...>& value, FormatContext& ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
798 |
std::integral_constant<size_t, N>) const -> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
799 |
typename FormatContext::iterator { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
800 |
auto out = std::get<sizeof...(T) - N>(formatters_) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
801 |
.format(std::get<sizeof...(T) - N>(value.tuple), ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
802 |
if (N <= 1) return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
803 |
out = detail::copy<Char>(value.sep, out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
804 |
ctx.advance_to(out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
805 |
return do_format(value, ctx, std::integral_constant<size_t, N - 1>()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
806 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
807 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
808 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
809 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
810 |
// Check if T has an interface like a container adaptor (e.g. std::stack, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
811 |
// std::queue, std::priority_queue). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
812 |
template <typename T> class is_container_adaptor_like { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
813 |
template <typename U> static auto check(U* p) -> typename U::container_type; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
814 |
template <typename> static void check(...); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
815 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
816 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
817 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
818 |
!std::is_void<decltype(check<T>(nullptr))>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
819 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
820 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
821 |
template <typename Container> struct all { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
822 |
const Container& c; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
823 |
auto begin() const -> typename Container::const_iterator { return c.begin(); } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
824 |
auto end() const -> typename Container::const_iterator { return c.end(); } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
825 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
826 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
827 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
828 |
template <typename T, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
829 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
830 |
T, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
831 |
enable_if_t<conjunction<detail::is_container_adaptor_like<T>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
832 |
bool_constant<range_format_kind<T, Char>::value == |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
833 |
range_format::disabled>>::value>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
834 |
: formatter<detail::all<typename T::container_type>, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
835 |
using all = detail::all<typename T::container_type>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
836 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
837 |
auto format(const T& t, FormatContext& ctx) const -> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
838 |
struct getter : T { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
839 |
static auto get(const T& t) -> all { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
840 |
return {t.*(&getter::c)}; // Access c through the derived class. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
841 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
842 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
843 |
return formatter<all>::format(getter::get(t), ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
844 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
845 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
846 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
847 |
FMT_BEGIN_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
848 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
849 |
/** |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
850 |
* Returns an object that formats `std::tuple` with elements separated by `sep`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
851 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
852 |
* **Example**: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
853 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
854 |
* auto t = std::tuple<int, char>{1, 'a'}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
855 |
* fmt::print("{}", fmt::join(t, ", ")); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
856 |
* // Output: 1, a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
857 |
*/ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
858 |
template <typename... T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
859 |
FMT_CONSTEXPR auto join(const std::tuple<T...>& tuple, string_view sep) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
860 |
-> tuple_join_view<char, T...> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
861 |
return {tuple, sep}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
862 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
863 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
864 |
/** |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
865 |
* Returns an object that formats `std::initializer_list` with elements |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
866 |
* separated by `sep`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
867 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
868 |
* **Example**: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
869 |
* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
870 |
* fmt::print("{}", fmt::join({1, 2, 3}, ", ")); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
871 |
* // Output: "1, 2, 3" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
872 |
*/ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
873 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
874 |
auto join(std::initializer_list<T> list, string_view sep) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
875 |
-> join_view<const T*, const T*> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
876 |
return join(std::begin(list), std::end(list), sep); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
877 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
878 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
879 |
FMT_END_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
880 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
881 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
882 |
#endif // FMT_RANGES_H_ |
|
|
1970-01-01 00:00 |
883 |
|