Renamed insert to insert_range to avoid ambiguous overload; fixes #420 (#430)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-05-07 10:02:18 +08:00
committed by GitHub
parent 41194ad33c
commit f86cdb5ca3
+22 -12
View File
@@ -94,25 +94,19 @@ class Object {
auto max_size() const { return data_.max_size(); }
/// Inserts a new element at the end.
void insert(const value_type& _value) {
data_.push_back(_value);
template <class... Args>
void insert(const Args&... _values) {
(data_.push_back(_values), ...);
i_ = 0;
}
/// Inserts a new element at the end.
void insert(value_type&& _value) {
data_.emplace_back(std::move(_value));
template <class... Args>
void insert(Args&&... _values) {
(data_.emplace_back(std::move(_values)), ...);
i_ = 0;
}
/// Inserts several new elements at the end.
template <class InputIt>
void insert(InputIt _first, InputIt _last) {
for (auto it = _first; it != _last; ++it) {
insert(*it);
}
}
/// Inserts a new element at the end.
void insert(const std::string& _k, const T& _v) {
insert(std::make_pair(_k, _v));
@@ -152,6 +146,22 @@ class Object {
insert(_args...);
}
/// Inserts several new elements at the end.
template <class InputIt>
void insert_range(InputIt _first, InputIt _last) {
for (auto it = _first; it != _last; ++it) {
insert(*it);
}
}
/// Inserts several new elements at the end.
template <class RangeType>
void insert_range(RangeType _range) {
for (const auto& val : _range) {
insert(val);
}
}
/// Returns the element signified by the key or creates a new one.
T& operator[](const std::string& _key) {
const auto i = find(_key);