3#ifndef TETL_FLAT_SET_FLAT_SET_HPP
4#define TETL_FLAT_SET_FLAT_SET_HPP
57template <
typename Key,
typename Container,
typename Compare = etl::less<Key>>
85 requires(detail::RandomAccessRange<container_type>)
96 explicit constexpr flat_set(Compare
const& comp)
102 template <
typename InputIt>
103 constexpr flat_set(InputIt first, InputIt last, Compare
const& comp = Compare())
110 template <
typename InputIt>
112 : _container(first, last)
117 [[nodiscard]]
constexpr auto begin() noexcept ->
iterator {
return _container.begin(); }
121 [[nodiscard]]
constexpr auto end() noexcept ->
iterator {
return _container.end(); }
122 [[nodiscard]]
constexpr auto end() const noexcept ->
const_iterator {
return _container.end(); }
134 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return _container.empty(); }
137 [[nodiscard]]
constexpr auto size() const noexcept ->
size_type {
return _container.size(); }
140 [[nodiscard]]
constexpr auto max_size() const noexcept ->
size_type {
return _container.max_size(); }
143 template <
typename... Args>
149 if (it ==
end() or _compare(key, *it)) {
150 it = _container.emplace(it,
etl::move(key));
157 template <
typename... Args>
177 template <
typename InputIt>
178 constexpr auto insert(InputIt first, InputIt last) ->
void
180 while (first != last) {
186 template <
typename InputIt>
191 auto&& container =
etl::move(_container);
212 return _container.erase(first, last);
219 swap(_compare, other._compare);
220 swap(_container, other._container);
223 constexpr auto clear() noexcept ->
void { _container.clear(); }
234 if (it ==
end() or _compare(key, *it)) {
243 if (it ==
end() or _compare(key, *it)) {
249 template <
typename K>
250 requires etl::detail::is_transparent_v<Compare>
254 if (it ==
end() or _compare(key, *it)) {
260 template <
typename K>
261 requires etl::detail::is_transparent_v<Compare>
265 if (it ==
end() or _compare(key, *it)) {
273 template <
typename K>
274 requires etl::detail::is_transparent_v<Compare>
277 return find(key) ==
end() ? 0 : 1;
282 template <
typename K>
283 requires etl::detail::is_transparent_v<Compare>
284 [[nodiscard]]
constexpr auto contains(K
const& key)
const ->
bool
286 return count(key) == 1;
299 template <
typename K>
300 requires etl::detail::is_transparent_v<Compare>
306 template <
typename K>
307 requires etl::detail::is_transparent_v<Compare>
323 template <
typename K>
324 requires etl::detail::is_transparent_v<Compare>
330 template <
typename K>
331 requires etl::detail::is_transparent_v<Compare>
347 template <
typename K>
348 requires etl::detail::is_transparent_v<Compare>
354 template <
typename K>
355 requires etl::detail::is_transparent_v<Compare>
363 return etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
377 friend constexpr auto swap(
flat_set& x,
flat_set& y)
noexcept(
noexcept(x.swap(y))) ->
void {
return x.swap(y); }
384template <
typename Key,
typename Container,
typename Compare,
typename Pred>
390 c.erase(it, c.end());
#define TETL_NO_UNIQUE_ADDRESS
Definition attributes.hpp:41
constexpr auto equal_range(ForwardIt first, ForwardIt last, T const &value, Compare comp) -> pair< ForwardIt, ForwardIt >
Returns a range containing all elements equivalent to value in the range [first, last).
Definition equal_range.hpp:20
constexpr auto remove(ForwardIt first, ForwardIt last, T const &value) -> ForwardIt
Removes all elements satisfying specific criteria from the range [first, last) and returns a past-the...
Definition remove.hpp:15
constexpr auto remove_if(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
Removes all elements satisfying specific criteria from the range [first, last) and returns a past-the...
Definition remove_if.hpp:16
constexpr auto lower_bound(ForwardIt first, ForwardIt last, T const &value, Compare comp) noexcept -> ForwardIt
Returns an iterator pointing to the first element in the range [first, last) that is not less than (i...
Definition lower_bound.hpp:21
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp) -> bool
Checks if the first range [f1, l1) is lexicographically less than the second range [f2,...
Definition lexicographical_compare.hpp:17
constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, Predicate p) -> bool
Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)),...
Definition equal.hpp:18
constexpr auto upper_bound(ForwardIt first, ForwardIt last, T const &value, Compare comp) -> ForwardIt
Returns an iterator pointing to the first element in the range [first, last) that is greater than val...
Definition upper_bound.hpp:24
constexpr auto distance(It first, It last) -> typename iterator_traits< It >::difference_type
Returns the number of hops from first to last.
Definition distance.hpp:16
Definition adjacent_find.hpp:8
constexpr auto ref(T &t) noexcept -> reference_wrapper< T >
Function templates ref and cref are helper functions that generate an object of type reference_wrappe...
Definition reference_wrapper.hpp:103
constexpr auto make_pair(T1 &&t, T2 &&u) -> pair< decay_t< T1 >, decay_t< T2 > >
Creates a etl::pair object, deducing the target type from the types of arguments.
Definition pair.hpp:164
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249
constexpr auto erase_if(etl::flat_set< Key, Container, Compare > &c, Pred pred) -> typename etl::flat_set< Key, Container, Compare >::size_type
Definition flat_set.hpp:385
constexpr auto forward(remove_reference_t< T > ¶m) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18
constexpr bool is_nothrow_swappable_v
Definition is_nothrow_swappable.hpp:19
A flat_set is a container adaptor that provides an associative container interface that supports uniq...
Definition flat_set.hpp:58
typename Container::iterator iterator
Definition flat_set.hpp:67
constexpr auto erase(key_type const &key) -> size_type
Definition flat_set.hpp:202
Compare value_compare
Definition flat_set.hpp:62
constexpr auto lower_bound(K const &key) const -> const_iterator
Definition flat_set.hpp:308
constexpr auto upper_bound(K const &key) const -> const_iterator
Definition flat_set.hpp:332
typename Container::const_iterator const_iterator
Definition flat_set.hpp:68
constexpr auto erase(const_iterator first, const_iterator last) -> iterator
Definition flat_set.hpp:210
friend constexpr auto operator==(flat_set const &lhs, flat_set const &rhs) -> bool
Definition flat_set.hpp:361
constexpr auto erase(iterator position) -> iterator
Definition flat_set.hpp:198
constexpr auto insert(value_type &&x) -> etl::pair< iterator, bool >
Definition flat_set.hpp:165
Compare key_compare
Definition flat_set.hpp:60
constexpr auto find(key_type const &key) const -> const_iterator
Definition flat_set.hpp:240
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Definition flat_set.hpp:127
etl::reverse_iterator< const_iterator > const_reverse_iterator
Definition flat_set.hpp:70
constexpr auto insert(InputIt first, InputIt last) -> void
Definition flat_set.hpp:178
value_type const & const_reference
Definition flat_set.hpp:64
constexpr auto upper_bound(K const &key) -> iterator
Definition flat_set.hpp:325
constexpr auto upper_bound(key_type const &key) -> iterator
Definition flat_set.hpp:313
constexpr auto contains(key_type const &key) const -> bool
Definition flat_set.hpp:280
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Definition flat_set.hpp:126
constexpr auto contains(K const &key) const -> bool
Definition flat_set.hpp:284
friend constexpr auto operator<=(flat_set const &x, flat_set const &y) -> bool
Definition flat_set.hpp:373
Key value_type
Definition flat_set.hpp:61
typename Container::size_type size_type
Definition flat_set.hpp:65
constexpr auto lower_bound(key_type const &key) -> iterator
Definition flat_set.hpp:289
friend constexpr auto operator>(flat_set const &x, flat_set const &y) -> bool
Definition flat_set.hpp:371
constexpr auto equal_range(key_type const &key) -> etl::pair< iterator, iterator >
Definition flat_set.hpp:337
constexpr auto insert(value_type const &x) -> etl::pair< iterator, bool >
Definition flat_set.hpp:163
constexpr auto lower_bound(key_type const &key) const -> const_iterator
Definition flat_set.hpp:294
constexpr auto rend() noexcept -> reverse_iterator
Definition flat_set.hpp:129
value_type & reference
Definition flat_set.hpp:63
constexpr auto begin() noexcept -> iterator
Definition flat_set.hpp:117
constexpr flat_set(etl::sorted_unique_t, container_type cont)
Definition flat_set.hpp:90
constexpr auto end() noexcept -> iterator
Definition flat_set.hpp:121
constexpr auto begin() const noexcept -> const_iterator
Definition flat_set.hpp:118
constexpr auto replace(container_type &&container) -> void
Definition flat_set.hpp:196
constexpr auto cbegin() const noexcept -> const_iterator
Definition flat_set.hpp:119
constexpr auto count(K const &key) const -> size_type
Definition flat_set.hpp:275
constexpr auto find(key_type const &key) -> iterator
Definition flat_set.hpp:231
friend constexpr auto operator<(flat_set const &lhs, flat_set const &rhs) -> bool
Definition flat_set.hpp:366
constexpr flat_set(InputIt first, InputIt last, Compare const &comp=Compare())
Definition flat_set.hpp:103
constexpr auto empty() const noexcept -> bool
Returns true if the underlying container is empty.
Definition flat_set.hpp:134
constexpr auto clear() noexcept -> void
Definition flat_set.hpp:223
constexpr auto lower_bound(K const &key) -> iterator
Definition flat_set.hpp:301
constexpr auto value_comp() const -> value_compare
Definition flat_set.hpp:228
constexpr flat_set(etl::sorted_unique_t, InputIt first, InputIt last, Compare const &comp=Compare())
Definition flat_set.hpp:111
Container container_type
Definition flat_set.hpp:71
etl::reverse_iterator< iterator > reverse_iterator
Definition flat_set.hpp:69
constexpr auto swap(flat_set &other) noexcept(etl::is_nothrow_swappable_v< Container > &&etl::is_nothrow_swappable_v< Compare >) -> void
Definition flat_set.hpp:215
constexpr auto equal_range(key_type const &key) const -> etl::pair< const_iterator, const_iterator >
Definition flat_set.hpp:342
constexpr flat_set(Compare const &comp)
Definition flat_set.hpp:96
constexpr auto max_size() const noexcept -> size_type
Returns the max_size of the underlying container.
Definition flat_set.hpp:140
constexpr auto key_comp() const -> key_compare
Definition flat_set.hpp:226
friend constexpr auto swap(flat_set &x, flat_set &y) noexcept(noexcept(x.swap(y))) -> void
Definition flat_set.hpp:377
constexpr auto find(K const &key) const -> const_iterator
Definition flat_set.hpp:262
constexpr auto end() const noexcept -> const_iterator
Definition flat_set.hpp:122
constexpr auto emplace(Args &&... args) -> etl::pair< iterator, bool >
Definition flat_set.hpp:144
constexpr auto count(key_type const &key) const -> size_type
Definition flat_set.hpp:271
Key key_type
Definition flat_set.hpp:59
constexpr auto crend() const noexcept -> const_reverse_iterator
Definition flat_set.hpp:131
constexpr auto equal_range(K const &key) -> etl::pair< iterator, iterator >
Definition flat_set.hpp:349
typename Container::difference_type difference_type
Definition flat_set.hpp:66
constexpr auto insert(const_iterator position, value_type const &x) -> iterator
Definition flat_set.hpp:167
constexpr auto extract() &&-> container_type
Definition flat_set.hpp:189
constexpr auto upper_bound(key_type const &key) const -> const_iterator
Definition flat_set.hpp:318
constexpr auto rend() const noexcept -> const_reverse_iterator
Definition flat_set.hpp:130
constexpr auto equal_range(K const &key) const -> etl::pair< const_iterator, const_iterator >
Definition flat_set.hpp:356
friend constexpr auto operator>=(flat_set const &x, flat_set const &y) -> bool
Definition flat_set.hpp:375
constexpr auto erase(const_iterator position) -> iterator
Definition flat_set.hpp:200
constexpr auto size() const noexcept -> size_type
Returns the size of the underlying container.
Definition flat_set.hpp:137
constexpr auto cend() const noexcept -> const_iterator
Definition flat_set.hpp:123
constexpr auto find(K const &key) -> iterator
Definition flat_set.hpp:251
constexpr auto insert(const_iterator position, value_type &&x) -> iterator
Definition flat_set.hpp:172
constexpr auto emplace_hint(const_iterator, Args &&... args) -> iterator
Definition flat_set.hpp:158
constexpr auto rbegin() noexcept -> reverse_iterator
Definition flat_set.hpp:125
constexpr flat_set(container_type const &container)
Initializes c with etl::move(cont), value-initializes compare, sorts the range [begin(),...
Definition flat_set.hpp:84
constexpr auto insert(etl::sorted_unique_t, InputIt first, InputIt last) -> void
constexpr flat_set()
Definition flat_set.hpp:73
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:36
reverse_iterator is an iterator adaptor that reverses the direction of a given iterator....
Definition reverse_iterator.hpp:22
Definition sorted_unique.hpp:8