61 std::vector<T> values_{};
73 auto insert(
const T& v)
noexcept
75 auto it = std::lower_bound(values_.begin(), values_.end(), v);
76 return values_.insert(it, v);
78 auto contains(
const T& v)
const noexcept
80 auto it = std::lower_bound(values_.begin(), values_.end(), v);
81 return it != values_.end();
83 [[nodiscard]]
size_t size() const noexcept {
return values_.size(); }
84 void merge(
const SortedVector<T>& rhs)
noexcept { values_ = merge(values_, rhs.values_); }
89 using value_type = std::pair<K, V>;
91 std::vector<value_type> values_{};
94 static auto compare_function(
const value_type& kv0,
const value_type& kv1)
96 return kv0.first <=> kv1.first;
107 template <
class... Args>
110 std::function<
void(
const K& k0, V& v0, V& v1)> fct_merge,
115 auto it = std::lower_bound(values_.begin(), values_.end(), compare_function);
116 if (values_.end() != it)
118 auto& [k0, v0] = *it;
122 fct_merge(k0, v0, V{args...});
124 return std::pair{it,
true};
129 it = values_.insert(it, V{args...});
131 return std::pair{it,
false};
134 const value_type& kv,
135 std::function<
void(
const K& k0, V& v0, V& v1)> fct_merge
139 auto it = std::lower_bound(values_.begin(), values_.end(), compare_function);
140 if (values_.end() != it)
142 auto& [k0, v0] = *it;
147 fct_merge(k0, v0, v1);
153 return values_.insert(it, kv);
155 auto contains(
const value_type& v)
const noexcept
157 auto it = std::lower_bound(values_.begin(), values_.end(), compare_function);
158 return it != values_.end();
160 [[nodiscard]]
size_t size() const noexcept {
return values_.size(); }