27 explicit Container(size_t max_size)
31 template <
typename... Args>
32 bool emplace(Args&&... args) {
33 auto& seq_index = container_.
template get<0>();
34 auto result = seq_index.emplace_front(std::forward<Args>(args)...);
37 seq_index.relocate(seq_index.begin(), result.first);
38 }
else if (seq_index.size() > max_size_) {
44 bool insert(
const Value& value) {
return emplace(value); }
46 bool insert(Value&& value) {
return emplace(std::move(value)); }
48 template <
typename Tag,
typename Key>
49 auto find(
const Key& key) {
50 auto& primary_index = container_.
template get<Tag>();
51 auto it = primary_index.find(key);
53 if (it != primary_index.end()) {
54 auto& seq_index = container_.
template get<0>();
55 auto seq_it = container_.
template project<0>(it);
56 seq_index.relocate(seq_index.begin(), seq_it);
62 template <
typename Tag,
typename Key>
63 bool contains(
const Key& key) {
64 return this->
template find<Tag, Key>(key) != container_.
template get<Tag>().end();
67 template <
typename Tag,
typename Key>
68 bool erase(
const Key& key) {
69 return container_.
template get<Tag>().erase(key) > 0;
72 size_t size()
const {
return container_.size(); }
73 bool empty()
const {
return container_.empty(); }
74 size_t capacity()
const {
return max_size_; }
76 void set_capacity(size_t new_capacity) {
77 max_size_ = new_capacity;
78 auto& seq_index = container_.
template get<0>();
79 while (container_.size() > max_size_) {
84 void clear() { container_.clear(); }
86 template <
typename Tag>
88 return container_.
template get<Tag>().end();
92 using AdditionalIndices = boost::mpl::list<boost::multi_index::sequenced<> >;
94 using ExtendedIndexSpecifierList = boost::mpl::joint_view<AdditionalIndices, IndexSpecifierList>;
96 using BoostContainer = boost::multi_index::multi_index_container<Value, ExtendedIndexSpecifierList, Allocator>;
98 BoostContainer container_;