Atoms Crowd  7.0.0
Map.h
1 #pragma once
2 #include <ToolchefsSTL/Allocators/Allocator.h>
3 #include <ToolchefsSTL/Containers/Array.h>
4 
5 
6 namespace ToolchefsSTL
7 {
8  template<typename T, typename K>
9  class Map
10  {
11  public:
12 
13  typedef std::pair<T, K> Entry;
14 
15  template <class Iter>
17  {
18  ReverseIterator(Iter* ptr) : m_ptr(ptr) {}
19  ~ReverseIterator() = default;
20  Iter* operator +(size_t value) const { return m_ptr - value; }
21  Iter* operator -(size_t value) const { return m_ptr + value; }
22  Iter* operator ++() { return --m_ptr; }
23  Iter* operator --() { return ++m_ptr; }
24  bool operator ==(const ReverseIterator& rhs) const { return m_ptr == rhs.m_ptr; }
25  bool operator !=(const ReverseIterator& rhs) const { return m_ptr != rhs.m_ptr; }
26  Iter operator *() const { return *m_ptr; }
27  Iter* operator->() const { return m_ptr; }
28  Iter* m_ptr;
29  };
30 
31  typedef Entry value_type;
32  typedef Entry& reference_type;
33  typedef Entry* ptr_type;
34 
35  typedef Entry* iterator;
36  typedef const Entry* const_iterator;
39 
40  explicit Map(Allocator* allocator = defaultAllocator()) noexcept;
41 
42  ~Map() noexcept;
43 
44  Map(const Map& rhs) noexcept;
45 
46  Map& operator=(const Map& rhs) noexcept;
47 
48  Map(Map&& rhs) noexcept;
49 
50  Map& operator=(Map&& rhs) noexcept;
51 
52  bool operator==(const Map& rhs) const noexcept;
53 
54  void clear() noexcept;
55 
56  size_t size() const noexcept;
57 
58  size_t length() const noexcept;
59 
60  size_t capacity() const noexcept;
61 
62  void reserve(size_t new_capacity) noexcept;
63 
64  iterator find(const T& key) noexcept;
65 
66  const_iterator find(const T& key) const noexcept;
67 
68  constexpr K& operator[](const T& key) noexcept;
69 
70  constexpr K& operator[](T&& key) noexcept;
71 
72  iterator emplace(T&& key, K&& value) noexcept;
73 
74  iterator emplace(const T& key, const K& value) noexcept;
75 
77  iterator begin() noexcept;
78 
79  iterator end() noexcept;
80 
81  const_iterator cbegin() const noexcept;
82 
83  const_iterator cend() const noexcept;
84 
85  reverse_iterator rbegin() noexcept;
86 
87  reverse_iterator rend() noexcept;
88 
89  const_reverse_iterator crbegin() const noexcept;
90 
91  const_reverse_iterator crend() const noexcept;
92 
93  iterator erase(iterator it) noexcept;
94 
95  void erase(const T& key) noexcept;
96 
97  private:
98 
99  Array<Entry> m_data;
100 
101  };
102 }
103 
104 #include "Map.impl.h"
Definition: Allocator.h:10
Definition: Array.h:10
Definition: Map.h:10
iterator begin() noexcept
Iterators.
Definition: Map.impl.h:153