momo  3.11
set_map_utility.h
Go to the documentation of this file.
1 /**********************************************************\
2 
3  This file is part of the
4  https://github.com/morzhovets/momo
5  project, distributed under the MIT License. See
6  https://github.com/morzhovets/momo/blob/branch_cpp11/LICENSE
7  for details.
8 
9  momo/stdish/set_map_utility.h
10 
11 \**********************************************************/
12 
13 #ifndef MOMO_INCLUDE_GUARD_STDISH_SET_MAP_UTILITY
14 #define MOMO_INCLUDE_GUARD_STDISH_SET_MAP_UTILITY
15 
16 #ifdef __has_include
17 # if __has_include(<momo/Utility.h>)
18 # include <momo/Utility.h>
19 # endif
20 #endif
21 #ifndef MOMO_PARENT_HEADER
22 # include "../Utility.h"
23 #endif
24 
25 #include MOMO_PARENT_HEADER(SetUtility)
26 #include MOMO_PARENT_HEADER(MapUtility)
27 
28 #ifdef MOMO_HAS_CONTAINERS_RANGES
29 # include <ranges>
30 #endif
31 
32 namespace momo
33 {
34 
35 namespace stdish
36 {
37 
38 namespace internal
39 {
40  template<typename TSetExtractedItem>
42  {
43  protected:
44  typedef TSetExtractedItem SetExtractedItem;
45 
46  public:
47  typedef typename SetExtractedItem::Item value_type;
48  //allocator_type;
49 
50  public:
51  set_node_handle() noexcept
52  {
53  }
54 
56  noexcept(std::is_nothrow_move_constructible<SetExtractedItem>::value)
57  : mSetExtractedItem(std::move(node.mSetExtractedItem))
58  {
59  }
60 
61  set_node_handle(const set_node_handle&) = delete;
62 
63  template<typename Set>
64  explicit set_node_handle(Set& set, typename Set::const_iterator iter)
65  : mSetExtractedItem(set.get_nested_container(), iter)
66  {
67  }
68 
69  ~set_node_handle() = default;
70 
71  //set_node_handle& operator=(set_node_handle&&)
72 
74 
75  MOMO_NODISCARD bool empty() const noexcept
76  {
77  return mSetExtractedItem.IsEmpty();
78  }
79 
80  explicit operator bool() const noexcept
81  {
82  return !empty();
83  }
84 
85  const value_type& value() const
86  {
87  return mSetExtractedItem.GetItem();
88  }
89 
91  {
92  return mSetExtractedItem.GetItem();
93  }
94 
95  //allocator_type get_allocator() const
96 
97  //void swap(set_node_handle&)
98  //friend void swap(set_node_handle&, set_node_handle&)
99 
100  protected:
102  {
103  return mSetExtractedItem;
104  }
105 
106  private:
107  SetExtractedItem mSetExtractedItem;
108  };
109 
110  template<typename TMapExtractedPair>
112  {
113  protected:
114  typedef TMapExtractedPair MapExtractedPair;
115 
116  public:
117  typedef typename MapExtractedPair::Key key_type;
118  typedef typename MapExtractedPair::Value mapped_type;
119  //allocator_type;
120 
121  private:
122  template<typename Map>
123  struct ConstIteratorProxy : private Map::const_iterator
124  {
125  typedef typename Map::const_iterator ConstIterator;
126  MOMO_DECLARE_PROXY_FUNCTION(ConstIterator, GetBaseIterator)
127  };
128 
129  public:
130  map_node_handle() noexcept
131  {
132  }
133 
135  noexcept(std::is_nothrow_move_constructible<MapExtractedPair>::value)
136  : mMapExtractedPair(std::move(node.mMapExtractedPair))
137  {
138  }
139 
141 
142  template<typename Map>
143  explicit map_node_handle(Map& map, typename Map::const_iterator iter)
144  : mMapExtractedPair(map.get_nested_container(),
145  ConstIteratorProxy<Map>::GetBaseIterator(iter))
146  {
147  }
148 
149  ~map_node_handle() = default;
150 
151  //map_node_handle& operator=(map_node_handle&&)
152 
154 
155  MOMO_NODISCARD bool empty() const noexcept
156  {
157  return mMapExtractedPair.IsEmpty();
158  }
159 
160  explicit operator bool() const noexcept
161  {
162  return !empty();
163  }
164 
165  const key_type& key() const
166  {
167  return mMapExtractedPair.GetKey();
168  }
169 
171  {
172  return mMapExtractedPair.GetKey();
173  }
174 
175  const mapped_type& mapped() const
176  {
177  return mMapExtractedPair.GetValue();
178  }
179 
181  {
182  return mMapExtractedPair.GetValue();
183  }
184 
185  //allocator_type get_allocator() const
186 
187  //void swap(map_node_handle&)
188  //friend void swap(map_node_handle&, map_node_handle&)
189 
190  protected:
192  {
193  return mMapExtractedPair;
194  }
195 
196  private:
197  MapExtractedPair mMapExtractedPair;
198  };
199 
200  template<typename Iterator, typename NodeHandle>
202  {
203  Iterator position;
204  bool inserted;
205  NodeHandle node;
206  };
207 
208 #ifdef MOMO_HAS_DEDUCTION_GUIDES
209  template<typename Key, typename Allocator, typename Hasher,
210  typename EqualComparer = std::equal_to<Key>,
211  typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
212  typename = decltype(std::declval<Hasher&>()(std::declval<const Key&>())),
213  typename = decltype(std::declval<EqualComparer&>()(std::declval<const Key&>(),
214  std::declval<const Key&>()))>
215  class unordered_checker
216  {
217  };
218 
219  template<typename Key, typename Allocator,
220  typename LessComparer = std::less<Key>,
221  typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
222  typename = decltype(std::declval<LessComparer&>()(std::declval<const Key&>(),
223  std::declval<const Key&>()))>
224  class ordered_checker
225  {
226  };
227 #endif // MOMO_HAS_DEDUCTION_GUIDES
228 }
229 
230 } // namespace stdish
231 
232 } // namespace momo
233 
234 #endif // MOMO_INCLUDE_GUARD_STDISH_SET_MAP_UTILITY
momo::stdish::internal::set_node_handle::value_type
SetExtractedItem::Item value_type
Definition: set_map_utility.h:47
momo::stdish::map
momo::stdish::map is similar to std::map, but much more efficient in memory usage....
Definition: map.h:824
momo::stdish::internal::set_node_handle::ptGetExtractedItem
SetExtractedItem & ptGetExtractedItem() noexcept
Definition: set_map_utility.h:101
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(map_node_handle &&node) noexcept(std::is_nothrow_move_constructible< MapExtractedPair >::value)
Definition: set_map_utility.h:134
momo::stdish::internal::map_node_handle::mapped
const mapped_type & mapped() const
Definition: set_map_utility.h:175
momo::stdish::internal::insert_return_type
Definition: set_map_utility.h:202
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(Map &map, typename Map::const_iterator iter)
Definition: set_map_utility.h:143
momo::stdish::internal::set_node_handle::operator=
set_node_handle & operator=(const set_node_handle &)=delete
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(Set &set, typename Set::const_iterator iter)
Definition: set_map_utility.h:64
momo::stdish::set
momo::stdish::set is similar to std::set, but much more efficient in memory usage....
Definition: set.h:67
momo::stdish::internal::map_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: set_map_utility.h:155
momo::stdish::internal::map_node_handle::ptGetExtractedPair
MapExtractedPair & ptGetExtractedPair() noexcept
Definition: set_map_utility.h:191
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(const map_node_handle &)=delete
momo::stdish::internal::map_node_handle::MapExtractedPair
TMapExtractedPair MapExtractedPair
Definition: set_map_utility.h:114
momo::stdish::internal::insert_return_type::node
NodeHandle node
Definition: set_map_utility.h:205
momo::stdish::internal::map_node_handle
Definition: set_map_utility.h:112
momo::stdish::internal::map_node_handle::operator=
map_node_handle & operator=(const map_node_handle &)=delete
momo::stdish::internal::set_node_handle::value
value_type & value()
Definition: set_map_utility.h:90
momo
Definition: Array.h:26
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle() noexcept
Definition: set_map_utility.h:51
momo::stdish::internal::insert_return_type::inserted
bool inserted
Definition: set_map_utility.h:204
momo::stdish::internal::map_node_handle::key_type
MapExtractedPair::Key key_type
Definition: set_map_utility.h:117
momo::stdish::internal::set_node_handle::SetExtractedItem
TSetExtractedItem SetExtractedItem
Definition: set_map_utility.h:44
MOMO_DECLARE_PROXY_FUNCTION
#define MOMO_DECLARE_PROXY_FUNCTION(Object, Func)
Definition: Utility.h:126
momo::stdish::internal::set_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: set_map_utility.h:75
std
Definition: Array.h:1173
momo::stdish::internal::set_node_handle::value
const value_type & value() const
Definition: set_map_utility.h:85
momo::stdish::internal::map_node_handle::mapped_type
MapExtractedPair::Value mapped_type
Definition: set_map_utility.h:118
momo::stdish::internal::set_node_handle::~set_node_handle
~set_node_handle()=default
momo::stdish::internal::map_node_handle::key
const key_type & key() const
Definition: set_map_utility.h:165
momo::stdish::internal::set_node_handle
Definition: set_map_utility.h:42
momo::stdish::internal::insert_return_type::position
Iterator position
Definition: set_map_utility.h:203
momo::stdish::internal::map_node_handle::mapped
mapped_type & mapped()
Definition: set_map_utility.h:180
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(set_node_handle &&node) noexcept(std::is_nothrow_move_constructible< SetExtractedItem >::value)
Definition: set_map_utility.h:55
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle() noexcept
Definition: set_map_utility.h:130
Utility.h
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(const set_node_handle &)=delete
MOMO_NODISCARD
#define MOMO_NODISCARD
Definition: UserSettings.h:217
momo::stdish::internal::map_node_handle::key
key_type & key()
Definition: set_map_utility.h:170
momo::stdish::internal::map_node_handle::~map_node_handle
~map_node_handle()=default