Skip to content

Commit e1b9668

Browse files
Merge branch 'gabime:v1.x' into v1.x
2 parents a7298e5 + 3335c38 commit e1b9668

File tree

18 files changed

+3858
-4261
lines changed

18 files changed

+3858
-4261
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/
3636
* Gentoo: `emerge dev-libs/spdlog`
3737
* Arch Linux: `pacman -S spdlog`
3838
* openSUSE: `sudo zypper in spdlog-devel`
39+
* ALT Linux: `apt-get install libspdlog-devel`
3940
* vcpkg: `vcpkg install spdlog`
4041
* conan: `conan install --requires=spdlog/[*]`
4142
* conda: `conda install -c conda-forge spdlog`

include/spdlog/fmt/bundled/args.h

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "format.h" // std_string_view
1818

1919
FMT_BEGIN_NAMESPACE
20-
2120
namespace detail {
2221

2322
template <typename T> struct is_reference_wrapper : std::false_type {};
@@ -72,19 +71,13 @@ class dynamic_arg_list {
7271
* It can be implicitly converted into `fmt::basic_format_args` for passing
7372
* into type-erased formatting functions such as `fmt::vformat`.
7473
*/
75-
template <typename Context>
76-
class dynamic_format_arg_store
77-
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
78-
// Workaround a GCC template argument substitution bug.
79-
: public basic_format_args<Context>
80-
#endif
81-
{
74+
template <typename Context> class dynamic_format_arg_store {
8275
private:
8376
using char_type = typename Context::char_type;
8477

8578
template <typename T> struct need_copy {
8679
static constexpr detail::type mapped_type =
87-
detail::mapped_type_constant<T, Context>::value;
80+
detail::mapped_type_constant<T, char_type>::value;
8881

8982
enum {
9083
value = !(detail::is_reference_wrapper<T>::value ||
@@ -97,7 +90,7 @@ class dynamic_format_arg_store
9790
};
9891

9992
template <typename T>
100-
using stored_type = conditional_t<
93+
using stored_t = conditional_t<
10194
std::is_convertible<T, std::basic_string<char_type>>::value &&
10295
!detail::is_reference_wrapper<T>::value,
10396
std::basic_string<char_type>, T>;
@@ -112,41 +105,37 @@ class dynamic_format_arg_store
112105

113106
friend class basic_format_args<Context>;
114107

115-
auto get_types() const -> unsigned long long {
116-
return detail::is_unpacked_bit | data_.size() |
117-
(named_info_.empty()
118-
? 0ULL
119-
: static_cast<unsigned long long>(detail::has_named_args_bit));
120-
}
121-
122108
auto data() const -> const basic_format_arg<Context>* {
123109
return named_info_.empty() ? data_.data() : data_.data() + 1;
124110
}
125111

126112
template <typename T> void emplace_arg(const T& arg) {
127-
data_.emplace_back(detail::make_arg<Context>(arg));
113+
data_.emplace_back(arg);
128114
}
129115

130116
template <typename T>
131117
void emplace_arg(const detail::named_arg<char_type, T>& arg) {
132-
if (named_info_.empty()) {
133-
constexpr const detail::named_arg_info<char_type>* zero_ptr{nullptr};
134-
data_.insert(data_.begin(), {zero_ptr, 0});
135-
}
136-
data_.emplace_back(detail::make_arg<Context>(detail::unwrap(arg.value)));
118+
if (named_info_.empty())
119+
data_.insert(data_.begin(), basic_format_arg<Context>(nullptr, 0));
120+
data_.emplace_back(detail::unwrap(arg.value));
137121
auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
138122
data->pop_back();
139123
};
140124
std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
141125
guard{&data_, pop_one};
142126
named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
143-
data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
127+
data_[0] = {named_info_.data(), named_info_.size()};
144128
guard.release();
145129
}
146130

147131
public:
148132
constexpr dynamic_format_arg_store() = default;
149133

134+
operator basic_format_args<Context>() const {
135+
return basic_format_args<Context>(data(), static_cast<int>(data_.size()),
136+
!named_info_.empty());
137+
}
138+
150139
/**
151140
* Adds an argument into the dynamic store for later passing to a formatting
152141
* function.
@@ -164,7 +153,7 @@ class dynamic_format_arg_store
164153
*/
165154
template <typename T> void push_back(const T& arg) {
166155
if (detail::const_check(need_copy<T>::value))
167-
emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
156+
emplace_arg(dynamic_args_.push<stored_t<T>>(arg));
168157
else
169158
emplace_arg(detail::unwrap(arg));
170159
}
@@ -200,7 +189,7 @@ class dynamic_format_arg_store
200189
dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
201190
if (detail::const_check(need_copy<T>::value)) {
202191
emplace_arg(
203-
fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value)));
192+
fmt::arg(arg_name, dynamic_args_.push<stored_t<T>>(arg.value)));
204193
} else {
205194
emplace_arg(fmt::arg(arg_name, arg.value));
206195
}
@@ -210,17 +199,20 @@ class dynamic_format_arg_store
210199
void clear() {
211200
data_.clear();
212201
named_info_.clear();
213-
dynamic_args_ = detail::dynamic_arg_list();
202+
dynamic_args_ = {};
214203
}
215204

216205
/// Reserves space to store at least `new_cap` arguments including
217206
/// `new_cap_named` named arguments.
218207
void reserve(size_t new_cap, size_t new_cap_named) {
219208
FMT_ASSERT(new_cap >= new_cap_named,
220-
"Set of arguments includes set of named arguments");
209+
"set of arguments includes set of named arguments");
221210
data_.reserve(new_cap);
222211
named_info_.reserve(new_cap_named);
223212
}
213+
214+
/// Returns the number of elements in the store.
215+
size_t size() const noexcept { return data_.size(); }
224216
};
225217

226218
FMT_END_NAMESPACE

0 commit comments

Comments
 (0)