24 BEGIN_NAMESPACE_CONTAINERS
26 template <
typename KeyType,
typename ValueType>
65 const KeyType&
getKey(std::size_t pos)
const;
79 const ValueType&
operator[](std::size_t pos)
const;
91 const ValueType&
back()
const;
101 std::size_t
size()
const;
137 void swap(int32_t posA, int32_t posB);
212 std::vector<std::pair<KeyType, ValueType>> pairs;
213 std::map<KeyType, typename std::vector<std::pair<KeyType, ValueType>>::iterator> pairsMap;
215 void rebuildPairMap();
218 template <
typename KeyType,
typename ValueType>
223 template <
typename KeyType,
typename ValueType>
230 template <
typename KeyType,
typename ValueType>
241 template <
typename KeyType,
typename ValueType>
244 pairs = std::move(other.pairs);
248 other.pairsMap.clear();
251 template <
typename KeyType,
typename ValueType>
256 pairs = std::move(other.pairs);
260 other.pairsMap.clear();
265 template <
typename KeyType,
typename ValueType>
268 return pairs[pos].first;
271 template <
typename KeyType,
typename ValueType>
274 return pairs[pos].second;
277 template <
typename KeyType,
typename ValueType>
280 return pairs[pos].second;
283 template <
typename KeyType,
typename ValueType>
286 return pairs.back().second;
289 template <
typename KeyType,
typename ValueType>
292 return pairs.back().second;
295 template <
typename KeyType,
typename ValueType>
302 template <
typename KeyType,
typename ValueType>
308 template <
typename KeyType,
typename ValueType>
311 return pairs.empty();
314 template <
typename KeyType,
typename ValueType>
317 if (pairsMap.find(key) == pairsMap.end())
319 pairs.emplace_back();
320 (pairs.back()).first = key;
327 template <
typename KeyType,
typename ValueType>
330 auto it = pairs.erase(position.pointee);
335 template <
typename KeyType,
typename ValueType>
338 auto it = pairs.erase(pairs.begin() + pos);
343 template <
typename KeyType,
typename ValueType>
348 std::swap(pairs[posA], pairs[posB]);
353 template <
typename KeyType,
typename ValueType>
356 auto pairsMapIter = pairsMap.find(key);
358 if (pairsMapIter != pairsMap.end())
360 return iterator(pairsMapIter->second);
365 template <
typename KeyType,
typename ValueType>
368 auto pairsMapIter = pairsMap.find(key);
370 if (pairsMapIter != pairsMap.end())
372 return iterator(pairsMapIter->second);
377 template <
typename KeyType,
typename ValueType>
381 for (
auto pairIter = pairs.begin(); pairIter != pairs.end(); ++pairIter)
383 pairsMap.insert(std::make_pair(pairIter->first, pairIter));
387 END_NAMESPACE_CONTAINERS
VectorWithKeysIterator provides access to VectorWithKeys elements and it's keys.
const_iterator end() const
Definition: vector_with_keys.h:189
Definition: vector_with_keys.h:27
iterator erase(iterator position)
Erases an element at an iterator position.
Definition: vector_with_keys.h:328
ValueType & operator[](std::size_t pos)
Mutable access element at position.
Definition: vector_with_keys.h:272
VectorWithKeys< KeyType, ValueType > & operator=(const VectorWithKeys< KeyType, ValueType > &other)
Copy assignment.
Definition: vector_with_keys.h:231
void swap(int32_t posA, int32_t posB)
Swaps elements in container at indexed positions passed.
Definition: vector_with_keys.h:344
Definition: vector_with_keys_iterator.h:27
bool emplaceBackWithKey(const KeyType &key)
Constructs an additional element at the at the back of the container by calling a default constructor...
Definition: vector_with_keys.h:315
const_iterator cend() const
Definition: vector_with_keys.h:206
VectorWithKeys()
Default constructor.
Definition: vector_with_keys.h:219
void clear()
Deletes all objects in the container and sets the size to zero.
Definition: vector_with_keys.h:296
const KeyType & getKey(std::size_t pos) const
Definition: vector_with_keys.h:266
const_iterator begin() const
Definition: vector_with_keys.h:180
std::size_t size() const
Definition: vector_with_keys.h:303
const_iterator cbegin() const
Definition: vector_with_keys.h:198
Definition: vector_with_keys_iterator.h:57
iterator findByKey(const KeyType &key)
Searches for an element with a key value passed.
Definition: vector_with_keys.h:354
ValueType & back()
Mutable access to the last element in the container.
Definition: vector_with_keys.h:284
iterator begin()
Definition: vector_with_keys.h:162
iterator end()
Definition: vector_with_keys.h:171
bool empty() const
Definition: vector_with_keys.h:309