31#ifndef ETL_CONST_SET_INCLUDED
32#define ETL_CONST_SET_INCLUDED
36#if ETL_NOT_USING_CPP11
37 #error NOT SUPPORTED FOR C++03 OR BELOW
53 template <
typename TKey,
typename TKeyCompare>
58 using key_type = TKey;
59 using value_type = TKey;
60 using key_compare = TKeyCompare;
61 using value_compare = TKeyCompare;
62 using const_reference =
const value_type&;
63 using const_pointer =
const value_type*;
64 using const_iterator =
const value_type*;
65 using size_type = size_t;
72 ETL_CONSTEXPR14
bool is_valid() const ETL_NOEXCEPT
80 ETL_CONSTEXPR14 const_iterator
begin() const ETL_NOEXCEPT
88 ETL_CONSTEXPR14 const_iterator
cbegin() const ETL_NOEXCEPT
96 ETL_CONSTEXPR14 const_iterator
end() const ETL_NOEXCEPT
98 return element_list_end;
104 ETL_CONSTEXPR14 const_iterator
cend() const ETL_NOEXCEPT
106 return element_list_end;
112 ETL_CONSTEXPR14 const_pointer
data() const ETL_NOEXCEPT
123 ETL_CONSTEXPR14 const_iterator
find(
const key_type& key)
const ETL_NOEXCEPT
127 if ((itr !=
end()) && (keys_are_equal(*itr, key)))
142 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
143 ETL_CONSTEXPR14 const_iterator
find(
const K& key)
const ETL_NOEXCEPT
147 if ((itr !=
end()) && (keys_are_equal(*itr, key)))
160 ETL_CONSTEXPR14
bool contains(
const key_type& key)
const ETL_NOEXCEPT
171 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
172 ETL_CONSTEXPR14
bool contains(
const K& key)
const ETL_NOEXCEPT
182 ETL_CONSTEXPR14 size_type
count(
const key_type& key)
const ETL_NOEXCEPT
193 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
194 ETL_CONSTEXPR14 size_type
count(
const K& key)
const ETL_NOEXCEPT
207 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const key_type& key)
const ETL_NOEXCEPT
209 return etl::equal_range(
begin(),
end(), key, vcompare);
221 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
222 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const ETL_NOEXCEPT
224 return etl::equal_range(
begin(),
end(), key, vcompare);
233 ETL_CONSTEXPR14 const_iterator
lower_bound(
const key_type& key)
const ETL_NOEXCEPT
235 return etl::lower_bound(
begin(),
end(), key, vcompare);
245 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
246 ETL_CONSTEXPR14 const_iterator
lower_bound(
const K& key)
const ETL_NOEXCEPT
248 return etl::lower_bound(
begin(),
end(), key, vcompare);
257 ETL_CONSTEXPR14 const_iterator
upper_bound(
const key_type& key)
const ETL_NOEXCEPT
259 return etl::upper_bound(
begin(),
end(), key, vcompare);
269 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
270 ETL_CONSTEXPR14 const_iterator
upper_bound(
const K& key)
const ETL_NOEXCEPT
272 return etl::upper_bound(
begin(),
end(), key, vcompare);
279 ETL_CONSTEXPR14 size_type
empty() const ETL_NOEXCEPT
288 ETL_CONSTEXPR14 size_type
full() const ETL_NOEXCEPT
290 return (max_elements != 0) && (
size() == max_elements);
297 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
299 return size_type(element_list_end - element_list);
306 ETL_CONSTEXPR14 size_type
max_size() const ETL_NOEXCEPT
316 ETL_CONSTEXPR14 size_type
capacity() const ETL_NOEXCEPT
325 ETL_CONSTEXPR14 key_compare
key_comp() const ETL_NOEXCEPT
327 return key_compare();
334 ETL_CONSTEXPR14 value_compare
value_comp() const ETL_NOEXCEPT
336 return value_compare();
344 template <
typename... TElements>
345 ETL_CONSTEXPR14
explicit iconst_set(
const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
346 : element_list(element_list_)
347 , element_list_end{element_list_ + size_}
348 , max_elements(max_elements_)
357 ETL_CONSTEXPR14
bool keys_are_equal(const_reference key1, const_reference key2)
const ETL_NOEXCEPT
359 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
366 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
367 ETL_CONSTEXPR14
bool keys_are_equal(
const K1& key1,
const K2& key2)
const ETL_NOEXCEPT
369 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
372 key_compare kcompare;
373 value_compare vcompare;
375 const value_type* element_list;
376 const value_type* element_list_end;
377 size_type max_elements;
383 template <
typename TKey,
size_t Size,
typename TKeyCompare = etl::less<TKey>>
390 using key_type =
typename base_t::key_type;
391 using value_type =
typename base_t::value_type;
392 using key_compare =
typename base_t::key_compare;
393 using const_reference =
typename base_t::const_reference;
394 using const_pointer =
typename base_t::const_pointer;
395 using const_iterator =
typename base_t::const_iterator;
396 using size_type =
typename base_t::size_type;
401 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
408 template <
typename... TElements>
409 ETL_CONSTEXPR14
explicit const_set(TElements&&... elements) ETL_NOEXCEPT
411 , element_list{etl::forward<TElements>(elements)...}
413 static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value),
"All elements must be key_type");
414 static_assert(
sizeof...(elements) <= Size,
"Number of elements exceeds capacity");
419 value_type element_list[Size];
426 template <
typename... TElements>
427 const_set(TElements...) ->
const_set<etl::nth_type_t<0, TElements...>,
sizeof...(TElements)>;
433 template <
typename TKey,
typename TKeyCompare = etl::less<TKey>>
440 using key_type =
typename base_t::key_type;
441 using value_type =
typename base_t::value_type;
442 using key_compare =
typename base_t::key_compare;
443 using const_reference =
typename base_t::const_reference;
444 using const_pointer =
typename base_t::const_pointer;
445 using const_iterator =
typename base_t::const_iterator;
446 using size_type =
typename base_t::size_type;
448 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
454 :
iconst_set<TKey, TKeyCompare>(
nullptr, 0, 0)
461 template <
size_type Size>
470 template <
size_type Size>
471 ETL_CONSTEXPR14
explicit const_set_ext(
const value_type(&begin_)[Size]) ETL_NOEXCEPT
481 template <
typename TElements,
size_t Size>
484 template <
typename TElements,
size_t Size>
485 const_set_ext(
const TElements(&)[Size]) -> const_set_ext<TElements>;
491 template <
typename TKey,
typename TKeyCompare>
495 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
501 template <
typename TKey,
typename TKeyCompare>
505 return !(lhs == rhs);
511 template <
typename TKey,
typename TKeyCompare>
515 return etl::lexicographical_compare(lhs.begin(), lhs.end(),
516 rhs.begin(), rhs.end(),
523 template <
typename TKey,
typename TKeyCompare>
533 template <
typename TKey,
typename TKeyCompare>
543 template <
typename TKey,
typename TKeyCompare>
ETL_CONSTEXPR14 const_set_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT
Construct a const_set from an array.
Definition const_set.h:471
ETL_CONSTEXPR14 const_set_ext() ETL_NOEXCEPT
Default construct a const_set.
Definition const_set.h:453
ETL_CONSTEXPR14 const_set_ext(const etl::span< const value_type, Size > &sp) ETL_NOEXCEPT
Construct a const_set from a variadic list of elements.
Definition const_set.h:462
Map type designed for constexpr.
Definition const_set.h:385
const key_type & const_key_reference
Defines the parameter types.
Definition const_set.h:399
ETL_CONSTEXPR14 const_set(TElements &&... elements) ETL_NOEXCEPT
Construct a const_set from a variadic list of elements. Static asserts if the elements are not of typ...
Definition const_set.h:409
Definition const_set.h:55
ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT
Definition const_set.h:325
ETL_CONSTEXPR14 bool contains(const key_type &key) const ETL_NOEXCEPT
Checks if the set contains an element with key.
Definition const_set.h:160
ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT
Definition const_set.h:297
ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT
Definition const_set.h:316
ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT
Definition const_set.h:72
ETL_CONSTEXPR14 const_iterator upper_bound(const key_type &key) const ETL_NOEXCEPT
Returns a const_iterator to the first element that is greater than the key. Returns a const_iterator ...
Definition const_set.h:257
ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT
Definition const_set.h:279
ETL_CONSTEXPR14 bool contains(const K &key) const ETL_NOEXCEPT
Checks if the set contains an element with key. Enabled if the comparator is transparent.
Definition const_set.h:172
ETL_CONSTEXPR14 const_iterator begin() const ETL_NOEXCEPT
Returns a const_iterator to the beginning of the set.
Definition const_set.h:80
ETL_CONSTEXPR14 ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(const key_type &key) const ETL_NOEXCEPT
Returns a range containing all elements with the key. The range is defined by a pair of two iterators...
Definition const_set.h:207
ETL_CONSTEXPR14 const_iterator lower_bound(const key_type &key) const ETL_NOEXCEPT
Returns a const_iterator to the first element that is not less than the key. Returns a const_iterator...
Definition const_set.h:233
ETL_CONSTEXPR14 const_iterator find(const K &key) const ETL_NOEXCEPT
Gets a const_iterator to the key. Enabled if the comparator is transparent.
Definition const_set.h:143
ETL_CONSTEXPR14 const_iterator cbegin() const ETL_NOEXCEPT
Returns a const_iterator to the beginning of the set.
Definition const_set.h:88
ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
Definition const_set.h:306
ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT
Definition const_set.h:288
ETL_CONSTEXPR14 const_iterator cend() const ETL_NOEXCEPT
Returns a const_iterator to the end of the set.
Definition const_set.h:104
ETL_CONSTEXPR14 const_iterator find(const key_type &key) const ETL_NOEXCEPT
Gets a const_iterator to the key.
Definition const_set.h:123
ETL_CONSTEXPR14 iconst_set(const value_type *element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
Constructor.
Definition const_set.h:345
ETL_CONSTEXPR14 size_type count(const K &key) const ETL_NOEXCEPT
Counts the numbeer elements with key. Enabled if the comparator is transparent.
Definition const_set.h:194
ETL_CONSTEXPR14 const_iterator end() const ETL_NOEXCEPT
Returns a const_iterator to the end of the set.
Definition const_set.h:96
ETL_CONSTEXPR14 const_pointer data() const ETL_NOEXCEPT
Returns a const_pointer to the beginning of the set.
Definition const_set.h:112
ETL_CONSTEXPR14 size_type count(const key_type &key) const ETL_NOEXCEPT
Counts the numbeer elements with key.
Definition const_set.h:182
ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT
Definition const_set.h:334
ETL_CONSTEXPR14 const_iterator upper_bound(const K &key) const ETL_NOEXCEPT
Returns a const_iterator to the first element that is greater than the key. Returns a const_iterator ...
Definition const_set.h:270
ETL_CONSTEXPR14 const_iterator lower_bound(const K &key) const ETL_NOEXCEPT
Returns a const_iterator to the first element that is not less than the key. Returns a const_iterator...
Definition const_set.h:246
ETL_CONSTEXPR14 ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(const K &key) const ETL_NOEXCEPT
Returns a range containing all elements with the key. The range is defined by a pair of two iterators...
Definition const_set.h:222
Span - Fixed Extent.
Definition span.h:138
ETL_NODISCARD ETL_CONSTEXPR14 bool is_unique_sorted(TIterator begin, TIterator end)
Definition algorithm.h:1794
bitset_ext
Definition absolute.h:39
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178