11 #ifndef UTIL_SET_VECTOR_H
12 #define UTIL_SET_VECTOR_H
21 # include <initializer_list>
22 # define NOEXCEPT noexcept
23 # define STD_FORWARD(T, V) std::forward<T>(V)
26 # define STD_FORWARD(T, V) (V)
36 template <
typename Key,
typename Compare = std::less<Key>,
class Allocator = std::allocator<Key> >
38 typedef std::vector<Key, Allocator> content_t;
53 typedef typename std::allocator_traits<allocator_type>::const_pointer
const_pointer;
59 typedef typename content_t::const_iterator
iterator;
68 explicit multiset_vector(
const Compare& comp = Compare(),
const Allocator& alloc = Allocator())
75 template <
typename InputIterator>
76 multiset_vector(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
77 const Allocator& alloc = Allocator())
78 : _content(first, last, alloc)
89 : _content(copy._content)
90 , _compare(copy._compare)
102 : _content(copy._content, alloc)
103 , _compare(copy._compare)
109 : _content(std::move(copy), alloc)
110 , _compare(std::move(copy._compare))
114 multiset_vector(std::initializer_list<value_type> values,
const Compare& comp = Compare(),
115 const Allocator& alloc = Allocator())
129 _content.assign(content.begin(), content.end());
136 _content = copy._content;
137 _compare = copy._compare;
143 return _content.get_allocator();
151 return _content.begin();
154 return _content.end();
158 return _content.begin();
161 return _content.end();
165 return _content.rbegin();
168 return _content.rend();
172 return _content.rbegin();
175 return _content.rend();
179 return _content.begin();
182 return _content.end();
186 return _content.rbegin();
189 return _content.rend();
202 return _content.at(i);
206 return _content.data();
210 return _content.front();
214 return _content.back();
228 return _content.empty();
231 return _content.size();
234 return _content.max_size();
238 void shrink_to_fit() {
239 _content.shrink_to_fit();
252 template <
typename ... Args>
iterator emplace(Args&& ... args)
254 auto value =
value_type(std::forward<Args>(args) ...);
255 return this->
_insert(std::move(value));
259 auto value =
value_type(std::forward<Args>(args) ...);
264 return this->
_insert(std::move(value));
271 void insert(std::initializer_list<value_type> values)
287 template <
typename InputIterator>
void insert(InputIterator first, InputIterator last)
290 _content.assign(first, last);
293 for(InputIterator it = first; it != last; ++it)
308 this->
erase(low, up);
322 swap(_content, other._content);
362 return std::distance(low, up);
387 typedef std::pair<const_iterator, const_iterator> const_result_t;
389 typedef std::pair<iterator, iterator> result_t;
395 typedef std::pair<const_iterator, const_iterator> result_t;
410 return not (v1 == v2);
417 for(; it1 != last_v1 and it2 != last_v2; ++it1, ++it2) {
420 else if(v1.
compare(*it2, *it1))
432 for(; it1 != last_v1 and it2 != last_v2; ++it1, ++it2) {
435 else if(v1.
compare(*it2, *it1))
444 return not (v1 > v2);
448 return not (v1 < v2);
453 return _content.begin() + (it -
begin());
458 if(_content.size() == 0)
460 std::sort(_content.begin(), _content.end(), this->key_comp());
465 return std::upper_bound(first, last, value, this->
key_comp());
470 if(hint == this->
end()) {
479 if(this->
compare(value, *hint)) {
480 if(hint == this->
begin())
483 if(this->
compare(*(--before), value))
486 }
else if(this->
compare(*hint, value)) {
488 if(++after == this->
end() or this->
compare(value, *after))
495 template <
typename T>
505 template <
typename T>
516 template <
typename T>
538 return _compare(k1, k2);
542 template <
typename Key,
typename Compare,
typename Allocator>
553 template <
typename Key,
typename Compare = std::less<Key>,
class Allocator = std::allocator<Key> >
578 explicit set_vector(
const Compare& comp = Compare(),
const Allocator& alloc = Allocator())
584 template <
typename InputIterator>
585 set_vector(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
586 const Allocator& alloc = Allocator())
614 : super_type(std::move(copy), alloc)
618 set_vector(std::initializer_list<value_type> values,
const Compare& comp = Compare(),
619 const Allocator& alloc = Allocator())
651 template <
typename ... Args> std::pair<iterator, bool> emplace(Args&& ... args)
653 auto value =
value_type(std::forward<Args>(args) ...);
654 return this->_insert(std::move(value));
656 template <
typename ... Args> std::pair<iterator, bool> emplace_hint(
const_iterator hint, Args&& ... args)
658 auto value =
value_type(std::forward<Args>(args) ...);
659 return this->_insert_hint(hint, std::move(value));
663 return this->_insert(std::move(value));
667 return this->_insert_hint(pos, value);
670 void insert(std::initializer_list<value_type> values)
679 return this->_insert(value);
684 return this->_insert_hint(pos, value);
687 template <
typename InputIterator>
void insert(InputIterator first, InputIterator last)
689 for(InputIterator it = first; it != last; ++it)
717 for(
size_t i = s - 1; i > 0; --i) {
718 if(this->
equiv_keys((*
this)[i], (*
this)[i - 1]))
726 typedef std::pair<const_iterator, bool> result_t;
728 return result_t(pos, (pos == last or this->
differ_keys(*pos, value)));
733 typedef std::pair<iterator, bool> result_t;
734 if(hint == this->
end()) {
735 if(this->
size() > 0) {
737 return result_t(this->
end(),
true);
739 return _find_insert_range(this->
begin(), this->
end(), value);
741 return result_t(this->
end(), value);
743 if(this->
compare(value, *hint)) {
744 if(hint == this->
begin())
745 return result_t(hint,
true);
747 if(this->
compare(*(--before), value))
748 return result_t(hint,
true);
749 return this->_find_insert_range(this->
begin(), before, value);
750 }
else if(this->
compare(*hint, value)) {
752 if(++after == this->
end() or this->
compare(value, *after))
753 return result_t(after,
true);
754 return this->_find_insert_range(after, this->
end(), value);
756 return result_t(hint,
false);
760 template <
typename T> std::pair<iterator, bool> _insert(T&& value)
762 std::pair<iterator, bool> _insert(
const value_type& value)
765 std::pair<iterator, bool> found = this->_find_insert_range(this->
begin(), this->
end(), value);
772 template <
typename T> std::pair<iterator, bool> _insert_hint(
const_iterator hint, T&& value)
777 std::pair<iterator, bool> found = this->_find_insert_hint(hint, value);
784 template <
typename Key,
typename Compare,
typename Allocator>