momo  3.10
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 #include "../SetUtility.h"
17 #include "../MapUtility.h"
18 
19 #ifdef MOMO_HAS_CONTAINERS_RANGES
20 # include <ranges>
21 #endif
22 
23 namespace momo
24 {
25 
26 namespace stdish
27 {
28 
29 namespace internal
30 {
31  template<typename TSetExtractedItem>
33  {
34  protected:
35  typedef TSetExtractedItem SetExtractedItem;
36 
37  public:
38  typedef typename SetExtractedItem::Item value_type;
39  //allocator_type;
40 
41  public:
42  set_node_handle() noexcept
43  {
44  }
45 
47  noexcept(std::is_nothrow_move_constructible<SetExtractedItem>::value)
48  : mSetExtractedItem(std::move(node.mSetExtractedItem))
49  {
50  }
51 
52  set_node_handle(const set_node_handle&) = delete;
53 
54  template<typename Set>
55  explicit set_node_handle(Set& set, typename Set::const_iterator iter)
56  : mSetExtractedItem(set.get_nested_container(), iter)
57  {
58  }
59 
60  ~set_node_handle() = default;
61 
62  //set_node_handle& operator=(set_node_handle&&)
63 
65 
66  MOMO_NODISCARD bool empty() const noexcept
67  {
68  return mSetExtractedItem.IsEmpty();
69  }
70 
71  explicit operator bool() const noexcept
72  {
73  return !empty();
74  }
75 
76  const value_type& value() const
77  {
78  return mSetExtractedItem.GetItem();
79  }
80 
82  {
83  return mSetExtractedItem.GetItem();
84  }
85 
86  //allocator_type get_allocator() const
87 
88  //void swap(set_node_handle&)
89  //friend void swap(set_node_handle&, set_node_handle&)
90 
91  protected:
93  {
94  return mSetExtractedItem;
95  }
96 
97  private:
98  SetExtractedItem mSetExtractedItem;
99  };
100 
101  template<typename TMapExtractedPair>
103  {
104  protected:
105  typedef TMapExtractedPair MapExtractedPair;
106 
107  public:
108  typedef typename MapExtractedPair::Key key_type;
109  typedef typename MapExtractedPair::Value mapped_type;
110  //allocator_type;
111 
112  private:
113  template<typename Map>
114  struct ConstIteratorProxy : private Map::const_iterator
115  {
116  typedef typename Map::const_iterator ConstIterator;
117  MOMO_DECLARE_PROXY_FUNCTION(ConstIterator, GetBaseIterator,
118  typename ConstIterator::BaseIterator)
119  };
120 
121  public:
122  map_node_handle() noexcept
123  {
124  }
125 
127  noexcept(std::is_nothrow_move_constructible<MapExtractedPair>::value)
128  : mMapExtractedPair(std::move(node.mMapExtractedPair))
129  {
130  }
131 
133 
134  template<typename Map>
135  explicit map_node_handle(Map& map, typename Map::const_iterator iter)
136  : mMapExtractedPair(map.get_nested_container(),
137  ConstIteratorProxy<Map>::GetBaseIterator(iter))
138  {
139  }
140 
141  ~map_node_handle() = default;
142 
143  //map_node_handle& operator=(map_node_handle&&)
144 
146 
147  MOMO_NODISCARD bool empty() const noexcept
148  {
149  return mMapExtractedPair.IsEmpty();
150  }
151 
152  explicit operator bool() const noexcept
153  {
154  return !empty();
155  }
156 
157  const key_type& key() const
158  {
159  return mMapExtractedPair.GetKey();
160  }
161 
163  {
164  return mMapExtractedPair.GetKey();
165  }
166 
167  const mapped_type& mapped() const
168  {
169  return mMapExtractedPair.GetValue();
170  }
171 
173  {
174  return mMapExtractedPair.GetValue();
175  }
176 
177  //allocator_type get_allocator() const
178 
179  //void swap(map_node_handle&)
180  //friend void swap(map_node_handle&, map_node_handle&)
181 
182  protected:
184  {
185  return mMapExtractedPair;
186  }
187 
188  private:
189  MapExtractedPair mMapExtractedPair;
190  };
191 
192  template<typename Iterator, typename NodeHandle>
194  {
195  Iterator position;
196  bool inserted;
197  NodeHandle node;
198  };
199 
200 #ifdef MOMO_HAS_DEDUCTION_GUIDES
201  template<typename Key, typename Allocator, typename HashFunc,
202  typename EqualFunc = std::equal_to<Key>,
203  typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
204  typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())),
205  typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(),
206  std::declval<const Key&>()))>
207  class unordered_checker
208  {
209  };
210 
211  template<typename Key, typename Allocator,
212  typename LessFunc = std::less<Key>,
213  typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
214  typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(),
215  std::declval<const Key&>()))>
216  class ordered_checker
217  {
218  };
219 #endif // MOMO_HAS_DEDUCTION_GUIDES
220 }
221 
222 } // namespace stdish
223 
224 } // namespace momo
225 
226 #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:38
momo::stdish::map
momo::stdish::map is similar to std::map, but much more efficient in memory usage....
Definition: map.h:837
momo::stdish::internal::set_node_handle::ptGetExtractedItem
SetExtractedItem & ptGetExtractedItem() noexcept
Definition: set_map_utility.h:92
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:126
momo::stdish::internal::map_node_handle::mapped
const mapped_type & mapped() const
Definition: set_map_utility.h:167
momo::stdish::internal::insert_return_type
Definition: set_map_utility.h:194
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(Map &map, typename Map::const_iterator iter)
Definition: set_map_utility.h:135
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:55
momo::stdish::set
momo::stdish::set is similar to std::set, but much more efficient in memory usage....
Definition: set.h:58
momo::stdish::internal::map_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: set_map_utility.h:147
momo::stdish::internal::map_node_handle::ptGetExtractedPair
MapExtractedPair & ptGetExtractedPair() noexcept
Definition: set_map_utility.h:183
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:105
momo::stdish::internal::insert_return_type::node
NodeHandle node
Definition: set_map_utility.h:197
momo::stdish::internal::map_node_handle
Definition: set_map_utility.h:103
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:81
momo
Definition: Array.h:26
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle() noexcept
Definition: set_map_utility.h:42
momo::stdish::internal::insert_return_type::inserted
bool inserted
Definition: set_map_utility.h:196
momo::stdish::internal::map_node_handle::key_type
MapExtractedPair::Key key_type
Definition: set_map_utility.h:108
momo::stdish::internal::set_node_handle::SetExtractedItem
TSetExtractedItem SetExtractedItem
Definition: set_map_utility.h:35
momo::stdish::internal::set_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: set_map_utility.h:66
std
Definition: ArrayUtility.h:308
momo::stdish::internal::set_node_handle::value
const value_type & value() const
Definition: set_map_utility.h:76
momo::stdish::internal::map_node_handle::mapped_type
MapExtractedPair::Value mapped_type
Definition: set_map_utility.h:109
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:157
momo::stdish::internal::set_node_handle
Definition: set_map_utility.h:33
momo::stdish::internal::insert_return_type::position
Iterator position
Definition: set_map_utility.h:195
momo::stdish::internal::map_node_handle::mapped
mapped_type & mapped()
Definition: set_map_utility.h:172
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:46
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle() noexcept
Definition: set_map_utility.h:122
MOMO_DECLARE_PROXY_FUNCTION
#define MOMO_DECLARE_PROXY_FUNCTION(Object, Func, Result)
Definition: Utility.h:116
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:203
momo::stdish::internal::map_node_handle::key
key_type & key()
Definition: set_map_utility.h:162
momo::stdish::internal::map_node_handle::~map_node_handle
~map_node_handle()=default