tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
static_set.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_SET_STATIC_SET_HPP
5#define TETL_SET_STATIC_SET_HPP
6
7#include <etl/_algorithm/lexicographical_compare.hpp>
8#include <etl/_algorithm/lower_bound.hpp>
9#include <etl/_algorithm/rotate.hpp>
10#include <etl/_contracts/check.hpp>
11#include <etl/_functional/less.hpp>
12#include <etl/_iterator/begin.hpp>
13#include <etl/_iterator/data.hpp>
14#include <etl/_iterator/end.hpp>
15#include <etl/_iterator/rbegin.hpp>
16#include <etl/_iterator/rend.hpp>
17#include <etl/_iterator/reverse_iterator.hpp>
18#include <etl/_iterator/size.hpp>
19#include <etl/_vector/static_vector.hpp>
20
21namespace etl {
22
23/// static_set is an associative container that contains a sorted set
24/// of unique objects of type Key. Sorting is done using the key comparison
25/// function Compare.
26///
27/// \headerfile etl/set.hpp
28/// \ingroup set
29template <typename Key, size_t Capacity, typename Compare = less<Key>>
30struct static_set {
31private:
32 // TODO: Currently static_set only supports default constructible
33 // comparators. This is because storing the Compare object would take up at
34 // least 1 extra byte. Probably even more because of alignment. The fix is
35 // to create a conditional storage struct depending on if the Compare
36 // template argument can be default constructed. If so: construct it on
37 // demand. If not: store it as a member.
38 static_assert(is_default_constructible_v<Compare>);
39
40 using storage_type = static_vector<Key, Capacity>;
41 storage_type _storage{};
42
43public:
44 using key_type = typename storage_type::value_type;
45 using value_type = typename storage_type::value_type;
46 using size_type = size_t;
47 using difference_type = ptrdiff_t;
48 using key_compare = Compare;
49 using value_compare = Compare;
50 using reference = value_type&;
51 using const_reference = value_type const&;
52 using pointer = typename storage_type::pointer;
53 using const_pointer = typename storage_type::const_pointer;
54 using iterator = typename storage_type::pointer;
55 using const_iterator = typename storage_type::const_pointer;
56 using reverse_iterator = etl::reverse_iterator<iterator>;
57 using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
58
59 /// \brief Constructs empty container.
60 constexpr static_set() = default;
61
62 /// \brief Constructs with the contents of the range [first, last). If
63 /// multiple elements in the range have keys that compare equivalent, all
64 /// but the first will be discarded.
65 template <typename InputIt>
66 requires(detail::InputIterator<InputIt>)
67 constexpr static_set(InputIt first, InputIt last)
68 {
69 if constexpr (detail::RandomAccessIterator<InputIt>) {
70 TETL_PRECONDITION(last - first >= 0);
71 TETL_PRECONDITION(static_cast<size_type>(last - first) <= max_size());
72 }
73
74 insert(first, last);
75 }
76
77 /// \brief
78 constexpr static_set(static_set const& other) = default;
79
80 /// \brief
81 constexpr static_set(static_set&& other) noexcept(noexcept(etl::move(declval<storage_type>()))) = default;
82
83 /// \brief
84 constexpr auto operator=(static_set const& other) -> static_set& = default;
85
86 /// \brief
87 constexpr auto operator=(static_set&& other) noexcept(noexcept(etl::move(declval<storage_type>())))
88 -> static_set& = default;
89
90 /// \brief Returns an iterator to the first element of the set.
91 [[nodiscard]] constexpr auto begin() noexcept -> iterator
92 {
93 return _storage.begin();
94 }
95
96 /// \brief Returns an iterator to the first element of the set.
97 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator
98 {
99 return _storage.begin();
100 }
101
102 /// \brief Returns an iterator to the first element of the set.
103 [[nodiscard]] constexpr auto cbegin() const noexcept -> const_iterator
104 {
105 return begin();
106 }
107
108 /// \brief Returns an iterator to the element following the last element of
109 /// the set.
110 [[nodiscard]] constexpr auto end() noexcept -> iterator
111 {
112 return _storage.end();
113 }
114
115 /// \brief Returns an iterator to the element following the last element of
116 /// the set.
117 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator
118 {
119 return _storage.end();
120 }
121
122 /// \brief Returns an iterator to the element following the last element of
123 /// the set.
124 [[nodiscard]] constexpr auto cend() const noexcept -> const_iterator
125 {
126 return end();
127 }
128
129 /// \brief Returns a reverse iterator to the first element of the reversed
130 /// set. It corresponds to the last element of the non-reversed set.
131 [[nodiscard]] constexpr auto rbegin() noexcept -> reverse_iterator
132 {
133 return reverse_iterator(end());
134 }
135
136 /// \brief Returns a reverse iterator to the first element of the reversed
137 /// set. It corresponds to the last element of the non-reversed set.
138 [[nodiscard]] constexpr auto rbegin() const noexcept -> const_reverse_iterator
139 {
140 return const_reverse_iterator(end());
141 }
142
143 /// \brief Returns a reverse iterator to the first element of the reversed
144 /// set. It corresponds to the last element of the non-reversed set.
145 [[nodiscard]] constexpr auto crbegin() const noexcept -> const_reverse_iterator
146 {
147 return rbegin();
148 }
149
150 /// \brief Returns a reverse iterator to the element following the last
151 /// element of the reversed set. It corresponds to the element preceding the
152 /// first element of the non-reversed set.
153 [[nodiscard]] constexpr auto rend() noexcept -> reverse_iterator
154 {
155 return reverse_iterator(begin());
156 }
157
158 /// \brief Returns a reverse iterator to the element following the last
159 /// element of the reversed set. It corresponds to the element preceding the
160 /// first element of the non-reversed set.
161 [[nodiscard]] constexpr auto rend() const noexcept -> const_reverse_iterator
162 {
163 return const_reverse_iterator(begin());
164 }
165
166 /// \brief Returns a reverse iterator to the element following the last
167 /// element of the reversed set. It corresponds to the element preceding the
168 /// first element of the non-reversed set.
169 [[nodiscard]] constexpr auto crend() const noexcept -> const_reverse_iterator
170 {
171 return rend();
172 }
173
174 /// \brief Checks if the container has no elements, i.e. whether begin() ==
175 /// end().
176 [[nodiscard]] constexpr auto empty() const noexcept -> bool
177 {
178 return _storage.empty();
179 }
180
181 /// \brief Checks if the container full, i.e. whether size() == Capacity.
182 [[nodiscard]] constexpr auto full() const noexcept -> bool
183 {
184 return _storage.full();
185 }
186
187 /// \brief Returns the number of elements in the container, i.e.
188 /// distance(begin(), end()).
189 [[nodiscard]] constexpr auto size() const noexcept -> size_type
190 {
191 return _storage.size();
192 }
193
194 /// \brief Returns the maximum number of elements the container is able to
195 /// hold.
196 [[nodiscard]] constexpr auto max_size() const noexcept -> size_type
197 {
198 return _storage.max_size();
199 }
200
201 /// \brief Erases all elements from the container. After this call, size()
202 /// returns zero.
203 constexpr auto clear() noexcept -> void
204 {
205 _storage.clear();
206 }
207
208 /// \brief Inserts element into the container, if the container doesn't
209 /// already contain an element with an equivalent key.
210 constexpr auto insert(value_type&& value) -> pair<iterator, bool>
211 requires(is_move_constructible_v<value_type>)
212 {
213 if (!full()) {
214 auto cmp = key_compare{};
215 auto* p = etl::lower_bound(_storage.begin(), _storage.end(), value, cmp);
216 if (p == _storage.end() || *(p) != value) {
217 _storage.push_back(etl::move(value));
218 auto* pos = rotate(p, _storage.end() - 1, _storage.end());
219 return make_pair(pos, true);
220 }
221 }
222
223 return pair<iterator, bool>(nullptr, false);
224 }
225
226 /// \brief Inserts element into the container, if the container doesn't
227 /// already contain an element with an equivalent key.
228 constexpr auto insert(value_type const& value) noexcept(noexcept(insert(etl::move(declval<key_type>()))))
229 -> pair<iterator, bool>
230 requires(is_copy_constructible_v<value_type>)
231 {
232 value_type tmp = value;
233 return insert(etl::move(tmp));
234 }
235
236 /// \brief Inserts elements from range [first, last). If multiple elements
237 /// in the range have keys that compare equivalent, it is unspecified which
238 /// element is inserted (pending LWG2844).
239 template <typename InputIter>
240 requires(detail::InputIterator<InputIter>)
241 constexpr auto insert(InputIter first, InputIter last) noexcept(noexcept(insert(declval<key_type>()))) -> void
242 {
243 for (; first != last; ++first) {
244 insert(*first);
245 }
246 }
247
248 /// \brief Inserts a new element into the container constructed in-place
249 /// with the given args if there is no element with the key in the
250 /// container.
251 template <typename... Args>
252 requires(is_copy_constructible_v<key_type>)
253 constexpr auto emplace(Args&&... args) noexcept(noexcept(insert(declval<key_type>()))) -> pair<iterator, bool>
254 {
255 return insert(value_type(etl::forward<Args>(args)...));
256 }
257
258 /// \brief Removes the element at pos.
259 ///
260 /// https://en.cppreference.com/w/cpp/container/set/erase
261 ///
262 /// \returns Iterator following the last removed element.
263 constexpr auto erase(iterator pos) noexcept -> iterator
264 {
265 return _storage.erase(pos);
266 }
267
268 /// \brief Removes the elements in the range [first; last), which must be a
269 /// valid range in *this.
270 ///
271 /// https://en.cppreference.com/w/cpp/container/set/erase
272 ///
273 /// \returns Iterator following the last removed element.
274 constexpr auto erase(iterator first, iterator last) -> iterator
275 {
276 auto res = first;
277 for (; first != last; ++first) {
278 res = erase(first);
279 }
280 return res;
281 }
282
283 /// \brief Removes the element (if one exists) with the key equivalent to
284 /// key.
285 ///
286 /// https://en.cppreference.com/w/cpp/container/set/erase
287 ///
288 /// \returns Number of elements removed.
289 constexpr auto erase(key_type const& key) noexcept -> size_type
290 {
291 if (auto* pos = etl::lower_bound(begin(), end(), key); pos != end()) {
292 erase(pos);
293 return 1;
294 }
295 return 0;
296 }
297
298 /// \brief Exchanges the contents of the container with those of other.
299 constexpr auto swap(static_set& other) noexcept(is_nothrow_swappable_v<key_type>) -> void
300 requires(is_assignable_v<key_type&, key_type &&>)
301 {
302 etl::swap(_storage, other._storage);
303 }
304
305 /// \brief Returns the number of elements with key that compares equivalent
306 /// to the specified argument, which is either 1 or 0 since this container
307 /// does not allow duplicates.
308 [[nodiscard]] constexpr auto count(key_type const& key) const noexcept -> size_type
309 {
310 return contains(key) ? 1 : 0;
311 }
312
313 /// \brief Returns the number of elements with key that compares equivalent
314 /// to the value x.
315 template <typename K>
316 requires(detail::is_transparent_v<key_compare>)
317 [[nodiscard]] constexpr auto count(K const& x) const -> size_type
318 {
319 return contains(x) ? 1 : 0;
320 }
321
322 /// \brief Finds an element with key equivalent to key.
323 ///
324 /// \returns Iterator to an element with key equivalent to key. If no such
325 /// element is found, past-the-end (see end()) iterator is returned.
326 [[nodiscard]] constexpr auto find(key_type const& key) noexcept -> iterator
327 {
328 return etl::find(begin(), end(), key);
329 }
330
331 /// \brief Finds an element with key equivalent to key.
332 ///
333 /// \returns Iterator to an element with key equivalent to key. If no such
334 /// element is found, past-the-end (see end()) iterator is returned.
335 [[nodiscard]] constexpr auto find(key_type const& key) const noexcept -> const_iterator
336 {
337 return etl::find(begin(), end(), key);
338 }
339
340 /// \brief Finds an element with key that compares equivalent to the value
341 /// x.
342 template <typename K>
343 requires(detail::is_transparent_v<key_compare>)
344 [[nodiscard]] constexpr auto find(K const& x) -> iterator
345 {
346 return find_if(begin(), end(), [&x](auto const& val) {
347 auto comp = key_compare();
348 return comp(val, x);
349 });
350 }
351
352 /// \brief Finds an element with key that compares equivalent to the value
353 /// x.
354 template <typename K>
355 requires(detail::is_transparent_v<key_compare>)
356 [[nodiscard]] constexpr auto find(K const& x) const -> const_iterator
357 {
358 return find_if(cbegin(), cend(), [&x](auto const& val) {
359 auto comp = key_compare();
360 return comp(val, x);
361 });
362 }
363
364 /// \brief Checks if there is an element with key equivalent to key in the
365 /// container.
366 [[nodiscard]] constexpr auto contains(key_type const& key) const noexcept -> bool
367 {
368 return find(key) != end();
369 }
370
371 /// \brief Checks if there is an element with key that compares equivalent
372 /// to the value x.
373 template <typename K>
374 requires(detail::is_transparent_v<key_compare>)
375 [[nodiscard]] constexpr auto contains(K const& x) const -> bool
376 {
377 return find(x) != end();
378 }
379
380 /// \brief Returns an iterator pointing to the first element that is not
381 /// less than (i.e. greater or equal to) key.
382 [[nodiscard]] constexpr auto lower_bound(key_type const& key) -> iterator
383 {
384 return etl::lower_bound(begin(), end(), key, key_compare{});
385 }
386
387 /// \brief Returns an iterator pointing to the first element that is not
388 /// less than (i.e. greater or equal to) key.
389 [[nodiscard]] constexpr auto lower_bound(key_type const& key) const -> const_iterator
390 {
391 return etl::lower_bound(begin(), end(), key, key_compare{});
392 }
393
394 /// \brief Returns an iterator pointing to the first element that is not
395 /// less than (i.e. greater or equal to) key.
396 template <typename K>
397 requires(detail::is_transparent_v<key_compare>)
398 [[nodiscard]] constexpr auto lower_bound(K const& key) -> iterator
399 {
400 return etl::lower_bound(begin(), end(), key, key_compare{});
401 }
402
403 /// \brief Returns an iterator pointing to the first element that is not
404 /// less than (i.e. greater or equal to) key.
405 template <typename K>
406 requires(detail::is_transparent_v<key_compare>)
407 [[nodiscard]] constexpr auto lower_bound(K const& key) const -> const_iterator
408 {
409 return etl::lower_bound(begin(), end(), key, key_compare{});
410 }
411
412 /// \brief Returns an iterator pointing to the first element that is greater
413 /// than key.
414 [[nodiscard]] constexpr auto upper_bound(key_type const& key) -> iterator
415 {
416 return etl::upper_bound(begin(), end(), key, key_compare{});
417 }
418
419 /// \brief Returns an iterator pointing to the first element that is greater
420 /// than key.
421 [[nodiscard]] constexpr auto upper_bound(key_type const& key) const -> const_iterator
422 {
423 return etl::upper_bound(begin(), end(), key, key_compare{});
424 }
425
426 /// \brief Returns an iterator pointing to the first element that is greater
427 /// than key.
428 template <typename K>
429 requires(detail::is_transparent_v<key_compare>)
430 [[nodiscard]] constexpr auto upper_bound(K const& key) -> iterator
431 {
432 return etl::upper_bound(begin(), end(), key, key_compare{});
433 }
434
435 /// \brief Returns an iterator pointing to the first element that is greater
436 /// than key.
437 template <typename K>
438 requires(detail::is_transparent_v<key_compare>)
439 [[nodiscard]] constexpr auto upper_bound(K const& key) const -> const_iterator
440 {
441 return etl::upper_bound(begin(), end(), key, key_compare{});
442 }
443
444 /// \brief Returns a range containing all elements with the given key in the
445 /// container. The range is defined by two iterators, one pointing to the
446 /// first element that is not less than key and another pointing to the
447 /// first element greater than key. Alternatively, the first iterator may be
448 /// obtained with lower_bound(), and the second with upper_bound().
449 [[nodiscard]] constexpr auto equal_range(key_type const& key) -> iterator
450 {
451 return etl::equal_range(begin(), end(), key, key_compare{});
452 }
453
454 /// \brief Returns a range containing all elements with the given key in the
455 /// container. The range is defined by two iterators, one pointing to the
456 /// first element that is not less than key and another pointing to the
457 /// first element greater than key. Alternatively, the first iterator may be
458 /// obtained with lower_bound(), and the second with upper_bound().
459 [[nodiscard]] constexpr auto equal_range(key_type const& key) const -> const_iterator
460 {
461 return etl::equal_range(begin(), end(), key, key_compare{});
462 }
463
464 /// \brief Returns a range containing all elements with the given key in the
465 /// container. The range is defined by two iterators, one pointing to the
466 /// first element that is not less than key and another pointing to the
467 /// first element greater than key. Alternatively, the first iterator may be
468 /// obtained with lower_bound(), and the second with upper_bound().
469 template <typename K>
470 requires(detail::is_transparent_v<key_compare>)
471 [[nodiscard]] constexpr auto equal_range(K const& key) -> iterator
472 {
473 return etl::equal_range(begin(), end(), key, key_compare{});
474 }
475
476 /// \brief Returns a range containing all elements with the given key in the
477 /// container. The range is defined by two iterators, one pointing to the
478 /// first element that is not less than key and another pointing to the
479 /// first element greater than key. Alternatively, the first iterator may be
480 /// obtained with lower_bound(), and the second with upper_bound().
481 template <typename K>
482 requires(detail::is_transparent_v<key_compare>)
483 [[nodiscard]] constexpr auto equal_range(K const& key) const -> const_iterator
484 {
485 return etl::equal_range(begin(), end(), key, key_compare{});
486 }
487
488 /// \brief Returns the function object that compares the keys, which is a
489 /// copy of this container's constructor argument comp. It is the same as
490 /// value_comp.
491 ///
492 /// \returns The key comparison function object.
493 [[nodiscard]] constexpr auto key_comp() const noexcept -> key_compare
494 {
495 return key_compare();
496 }
497
498 /// \brief Returns the function object that compares the values. It is the
499 /// same as key_comp.
500 ///
501 /// \returns The value comparison function object.
502 [[nodiscard]] constexpr auto value_comp() const noexcept -> value_compare
503 {
504 return value_compare();
505 }
506};
507
508/// \brief Compares the contents of two sets.
509///
510/// \details Checks if the contents of lhs and rhs are equal, that is, they have
511/// the same number of elements and each element in lhs compares equal with the
512/// element in rhs at the same position.
513template <typename Key, size_t Capacity, typename Comp>
514[[nodiscard]] constexpr auto
515operator==(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
516{
517 return lhs.size() == rhs.size() && equal(begin(lhs), end(lhs), begin(rhs));
518}
519
520/// \brief Compares the contents of two sets.
521///
522/// \details Checks if the contents of lhs and rhs are equal, that is, they have
523/// the same number of elements and each element in lhs compares equal with the
524/// element in rhs at the same position.
525template <typename Key, size_t Capacity, typename Comp>
526[[nodiscard]] constexpr auto
527operator!=(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
528{
529 return !(lhs == rhs);
530}
531
532/// \brief Compares the contents of two sets.
533///
534/// \details Compares the contents of lhs and rhs lexicographically. The
535/// comparison is performed by a function equivalent to
536/// lexicographical_compare. This comparison ignores the set's ordering
537/// Compare.
538template <typename Key, size_t Capacity, typename Comp>
539[[nodiscard]] constexpr auto
540operator<(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
541{
542 return lexicographical_compare(begin(lhs), end(lhs), begin(rhs), end(rhs));
543}
544
545/// \brief Compares the contents of two sets.
546///
547/// \details Compares the contents of lhs and rhs lexicographically. The
548/// comparison is performed by a function equivalent to
549/// lexicographical_compare. This comparison ignores the set's ordering
550/// Compare.
551template <typename Key, size_t Capacity, typename Comp>
552[[nodiscard]] constexpr auto
553operator<=(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
554{
555 return !(rhs < lhs);
556}
557
558/// \brief Compares the contents of two sets.
559///
560/// \details Compares the contents of lhs and rhs lexicographically. The
561/// comparison is performed by a function equivalent to
562/// lexicographical_compare. This comparison ignores the set's ordering
563/// Compare.
564template <typename Key, size_t Capacity, typename Comp>
565[[nodiscard]] constexpr auto
566operator>(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
567{
568 return rhs < lhs;
569}
570
571/// \brief Compares the contents of two sets.
572///
573/// \details Compares the contents of lhs and rhs lexicographically. The
574/// comparison is performed by a function equivalent to
575/// lexicographical_compare. This comparison ignores the set's ordering
576/// Compare.
577template <typename Key, size_t Capacity, typename Comp>
578[[nodiscard]] constexpr auto
579operator>=(static_set<Key, Capacity, Comp> const& lhs, static_set<Key, Capacity, Comp> const& rhs) -> bool
580{
581 return !(lhs < rhs);
582}
583
584/// \brief Specializes the swap algorithm for set. Swaps the contents
585/// of lhs and rhs. Calls lhs.swap(rhs).
586template <typename Key, size_t Capacity, typename Compare>
587constexpr auto
588swap(static_set<Key, Capacity, Compare>& lhs, static_set<Key, Capacity, Compare>& rhs) noexcept(noexcept(lhs.swap(rhs)))
589 -> void
590{
591 lhs.swap(rhs);
592}
593
594// /// \brief Erases all elements that satisfy the predicate pred from the
595// container.
596// ///
597// /// https://en.cppreference.com/w/cpp/container/set/erase_if
598// template <typename Key, size_t Capacity, typename Compare, typename
599// Predicate> constexpr auto erase_if(static_set<Key, Capacity, Compare>&
600// c, Predicate pred) ->
601// typename static_set<Key, Capacity, Compare>::size_type
602// {
603// auto const old_size = c.size();
604// for (auto i = c.begin(), last = c.end(); i != last;)
605// {
606// if (pred(*i)) { i = c.erase(i); }
607// else
608// {
609// ++i;
610// }
611// }
612
613// return old_size - c.size();
614// }
615
616} // namespace etl
617
618#endif // TETL_SET_STATIC_SET_HPP
Definition adjacent_find.hpp:9
constexpr auto swap(static_set< Key, Capacity, Compare > &lhs, static_set< Key, Capacity, Compare > &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
Specializes the swap algorithm for set. Swaps the contents of lhs and rhs. Calls lhs....
Definition static_set.hpp:588
constexpr auto operator>(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:566
constexpr auto operator!=(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:527
constexpr auto operator<=(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:553
constexpr auto operator<(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:540
constexpr auto operator>=(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:579
constexpr auto operator==(static_set< Key, Capacity, Comp > const &lhs, static_set< Key, Capacity, Comp > const &rhs) -> bool
Compares the contents of two sets.
Definition static_set.hpp:515
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37
static_set is an associative container that contains a sorted set of unique objects of type Key....
Definition static_set.hpp:30
constexpr auto equal_range(key_type const &key) -> iterator
Returns a range containing all elements with the given key in the container. The range is defined by ...
Definition static_set.hpp:449
constexpr auto equal_range(K const &key) -> iterator
Returns a range containing all elements with the given key in the container. The range is defined by ...
Definition static_set.hpp:471
constexpr auto lower_bound(K const &key) const -> const_iterator
Returns an iterator pointing to the first element that is not less than (i.e. greater or equal to) ke...
Definition static_set.hpp:407
constexpr auto find(key_type const &key) const noexcept -> const_iterator
Finds an element with key equivalent to key.
Definition static_set.hpp:335
constexpr auto contains(key_type const &key) const noexcept -> bool
Checks if there is an element with key equivalent to key in the container.
Definition static_set.hpp:366
constexpr auto emplace(Args &&... args) noexcept(noexcept(insert(declval< key_type >()))) -> pair< iterator, bool >
Inserts a new element into the container constructed in-place with the given args if there is no elem...
Definition static_set.hpp:253
constexpr static_set(static_set &&other) noexcept(noexcept(etl::move(declval< storage_type >())))=default
constexpr auto erase(key_type const &key) noexcept -> size_type
Removes the element (if one exists) with the key equivalent to key.
Definition static_set.hpp:289
constexpr auto value_comp() const noexcept -> value_compare
Returns the function object that compares the values. It is the same as key_comp.
Definition static_set.hpp:502
constexpr auto find(key_type const &key) noexcept -> iterator
Finds an element with key equivalent to key.
Definition static_set.hpp:326
constexpr auto swap(static_set &other) noexcept(is_nothrow_swappable_v< key_type >) -> void requires(is_assignable_v< key_type &, key_type && >)
Exchanges the contents of the container with those of other.
Definition static_set.hpp:299
constexpr auto count(key_type const &key) const noexcept -> size_type
Returns the number of elements with key that compares equivalent to the specified argument,...
Definition static_set.hpp:308
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed set. It corresponds to the last eleme...
Definition static_set.hpp:145
constexpr auto upper_bound(key_type const &key) -> iterator
Returns an iterator pointing to the first element that is greater than key.
Definition static_set.hpp:414
constexpr auto upper_bound(K const &key) -> iterator
Returns an iterator pointing to the first element that is greater than key.
Definition static_set.hpp:430
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed set. It corresponds to the last eleme...
Definition static_set.hpp:138
constexpr auto lower_bound(key_type const &key) -> iterator
Returns an iterator pointing to the first element that is not less than (i.e. greater or equal to) ke...
Definition static_set.hpp:382
constexpr auto find(K const &x) -> iterator
Finds an element with key that compares equivalent to the value x.
Definition static_set.hpp:344
constexpr static_set()=default
Constructs empty container.
constexpr static_set(InputIt first, InputIt last)
Constructs with the contents of the range [first, last). If multiple elements in the range have keys ...
Definition static_set.hpp:67
constexpr auto lower_bound(key_type const &key) const -> const_iterator
Returns an iterator pointing to the first element that is not less than (i.e. greater or equal to) ke...
Definition static_set.hpp:389
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed set....
Definition static_set.hpp:153
constexpr auto begin() noexcept -> iterator
Returns an iterator to the first element of the set.
Definition static_set.hpp:91
constexpr auto insert(InputIter first, InputIter last) noexcept(noexcept(insert(declval< key_type >()))) -> void
Inserts elements from range [first, last). If multiple elements in the range have keys that compare e...
Definition static_set.hpp:241
constexpr auto end() noexcept -> iterator
Returns an iterator to the element following the last element of the set.
Definition static_set.hpp:110
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the first element of the set.
Definition static_set.hpp:97
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first element of the set.
Definition static_set.hpp:103
constexpr auto insert(value_type const &value) noexcept(noexcept(insert(etl::move(declval< key_type >())))) -> pair< iterator, bool > requires(is_copy_constructible_v< value_type >)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition static_set.hpp:228
constexpr auto empty() const noexcept -> bool
Checks if the container has no elements, i.e. whether begin() == end().
Definition static_set.hpp:176
constexpr auto clear() noexcept -> void
Erases all elements from the container. After this call, size() returns zero.
Definition static_set.hpp:203
constexpr auto find(K const &x) const -> const_iterator
Finds an element with key that compares equivalent to the value x.
Definition static_set.hpp:356
constexpr auto equal_range(K const &key) const -> const_iterator
Returns a range containing all elements with the given key in the container. The range is defined by ...
Definition static_set.hpp:483
constexpr auto count(K const &x) const -> size_type
Returns the number of elements with key that compares equivalent to the value x.
Definition static_set.hpp:317
constexpr auto full() const noexcept -> bool
Checks if the container full, i.e. whether size() == Capacity.
Definition static_set.hpp:182
constexpr auto contains(K const &x) const -> bool
Checks if there is an element with key that compares equivalent to the value x.
Definition static_set.hpp:375
constexpr auto max_size() const noexcept -> size_type
Returns the maximum number of elements the container is able to hold.
Definition static_set.hpp:196
constexpr auto end() const noexcept -> const_iterator
Returns an iterator to the element following the last element of the set.
Definition static_set.hpp:117
constexpr auto upper_bound(K const &key) const -> const_iterator
Returns an iterator pointing to the first element that is greater than key.
Definition static_set.hpp:439
constexpr auto equal_range(key_type const &key) const -> const_iterator
Returns a range containing all elements with the given key in the container. The range is defined by ...
Definition static_set.hpp:459
constexpr auto operator=(static_set &&other) noexcept(noexcept(etl::move(declval< storage_type >()))) -> static_set &=default
constexpr static_set(static_set const &other)=default
constexpr auto lower_bound(K const &key) -> iterator
Returns an iterator pointing to the first element that is not less than (i.e. greater or equal to) ke...
Definition static_set.hpp:398
constexpr auto crend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed set....
Definition static_set.hpp:169
constexpr auto insert(value_type &&value) -> pair< iterator, bool > requires(is_move_constructible_v< value_type >)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition static_set.hpp:210
constexpr auto erase(iterator pos) noexcept -> iterator
Removes the element at pos.
Definition static_set.hpp:263
constexpr auto erase(iterator first, iterator last) -> iterator
Removes the elements in the range [first; last), which must be a valid range in *this.
Definition static_set.hpp:274
constexpr auto upper_bound(key_type const &key) const -> const_iterator
Returns an iterator pointing to the first element that is greater than key.
Definition static_set.hpp:421
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed set....
Definition static_set.hpp:161
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the container, i.e. distance(begin(), end()).
Definition static_set.hpp:189
constexpr auto cend() const noexcept -> const_iterator
Returns an iterator to the element following the last element of the set.
Definition static_set.hpp:124
constexpr auto operator=(static_set const &other) -> static_set &=default
constexpr auto key_comp() const noexcept -> key_compare
Returns the function object that compares the keys, which is a copy of this container's constructor a...
Definition static_set.hpp:493
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed set. It corresponds to the last eleme...
Definition static_set.hpp:131
Dynamically-resizable fixed-capacity vector.
Definition static_vector.hpp:401