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);
235 ETL_CONSTEXPR14 const_iterator
lower_bound(
const key_type& key)
const ETL_NOEXCEPT
237 return etl::lower_bound(
begin(),
end(), key, vcompare);
248 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
249 ETL_CONSTEXPR14 const_iterator
lower_bound(
const K& key)
const ETL_NOEXCEPT
251 return etl::lower_bound(
begin(),
end(), key, vcompare);
262 ETL_CONSTEXPR14 const_iterator
upper_bound(
const key_type& key)
const ETL_NOEXCEPT
264 return etl::upper_bound(
begin(),
end(), key, vcompare);
275 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
276 ETL_CONSTEXPR14 const_iterator
upper_bound(
const K& key)
const ETL_NOEXCEPT
278 return etl::upper_bound(
begin(),
end(), key, vcompare);
285 ETL_CONSTEXPR14 size_type
empty() const ETL_NOEXCEPT
294 ETL_CONSTEXPR14 size_type
full() const ETL_NOEXCEPT
296 return (max_elements != 0) && (
size() == max_elements);
303 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
305 return size_type(element_list_end - element_list);
312 ETL_CONSTEXPR14 size_type
max_size() const ETL_NOEXCEPT
322 ETL_CONSTEXPR14 size_type
capacity() const ETL_NOEXCEPT
331 ETL_CONSTEXPR14 key_compare
key_comp() const ETL_NOEXCEPT
333 return key_compare();
340 ETL_CONSTEXPR14 value_compare
value_comp() const ETL_NOEXCEPT
342 return value_compare();
350 template <
typename... TElements>
351 ETL_CONSTEXPR14
explicit iconst_set(
const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
352 : element_list(element_list_)
353 , element_list_end{element_list_ + size_}
354 , max_elements(max_elements_)
363 ETL_CONSTEXPR14
bool keys_are_equal(const_reference key1, const_reference key2)
const ETL_NOEXCEPT
365 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
372 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
373 ETL_CONSTEXPR14
bool keys_are_equal(
const K1& key1,
const K2& key2)
const ETL_NOEXCEPT
375 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
378 key_compare kcompare;
379 value_compare vcompare;
381 const value_type* element_list;
382 const value_type* element_list_end;
383 size_type max_elements;
389 template <
typename TKey,
size_t Size,
typename TKeyCompare = etl::less<TKey>>
396 using key_type =
typename base_t::key_type;
397 using value_type =
typename base_t::value_type;
398 using key_compare =
typename base_t::key_compare;
399 using const_reference =
typename base_t::const_reference;
400 using const_pointer =
typename base_t::const_pointer;
401 using const_iterator =
typename base_t::const_iterator;
402 using size_type =
typename base_t::size_type;
407 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
415 template <
typename... TElements>
416 ETL_CONSTEXPR14
explicit const_set(TElements&&... elements) ETL_NOEXCEPT
418 , element_list{etl::forward<TElements>(elements)...}
420 static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value),
"All elements must be key_type");
421 static_assert(
sizeof...(elements) <= Size,
"Number of elements exceeds capacity");
426 value_type element_list[Size];
433 template <
typename... TElements>
434 const_set(TElements...) ->
const_set<etl::nth_type_t<0, TElements...>,
sizeof...(TElements)>;
440 template <
typename TKey,
typename TKeyCompare = etl::less<TKey>>
447 using key_type =
typename base_t::key_type;
448 using value_type =
typename base_t::value_type;
449 using key_compare =
typename base_t::key_compare;
450 using const_reference =
typename base_t::const_reference;
451 using const_pointer =
typename base_t::const_pointer;
452 using const_iterator =
typename base_t::const_iterator;
453 using size_type =
typename base_t::size_type;
455 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
461 :
iconst_set<TKey, TKeyCompare>(
nullptr, 0, 0)
468 template <
size_type Size>
477 template <
size_type Size>
478 ETL_CONSTEXPR14
explicit const_set_ext(
const value_type (&begin_)[Size]) ETL_NOEXCEPT
488 template <
typename TElements,
size_t Size>
491 template <
typename TElements,
size_t Size>
492 const_set_ext(
const TElements (&)[Size]) -> const_set_ext<TElements>;
498 template <
typename TKey,
typename TKeyCompare>
501 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
507 template <
typename TKey,
typename TKeyCompare>
510 return !(lhs == rhs);
516 template <
typename TKey,
typename TKeyCompare>
519 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
525 template <
typename TKey,
typename TKeyCompare>
534 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:478
ETL_CONSTEXPR14 const_set_ext() ETL_NOEXCEPT
Default construct a const_set.
Definition const_set.h:460
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:469
Map type designed for constexpr.
Definition const_set.h:391
const key_type & const_key_reference
Defines the parameter types.
Definition const_set.h:405
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:416
Definition const_set.h:55
ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT
Definition const_set.h:331
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:303
ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT
Definition const_set.h:322
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:262
ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT
Definition const_set.h:285
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:235
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:312
ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT
Definition const_set.h:294
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:351
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:340
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:276
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:249
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:208
ETL_NODISCARD ETL_CONSTEXPR14 bool is_unique_sorted(TIterator begin, TIterator end)
Definition algorithm.h:1718
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1081
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1133
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1147
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1093
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1106
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1120