31#ifndef ETL_CONST_MAP_INCLUDED
32#define ETL_CONST_MAP_INCLUDED
36#if ETL_NOT_USING_CPP11
37 #error NOT SUPPORTED FOR C++03 OR BELOW
53 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
58 using key_type = TKey;
59 using value_type = ETL_OR_STD::pair<const TKey, TMapped>;
60 using mapped_type = TMapped;
61 using key_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;
75 ETL_CONSTEXPR14
bool operator()(
const value_type& element1,
const value_type& element2)
const ETL_NOEXCEPT
77 return kcompare(element1.first, element2.first);
81 ETL_CONSTEXPR14
bool operator()(
const value_type& element,
const key_type& key)
const ETL_NOEXCEPT
83 return kcompare(element.first, key);
88 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
89 ETL_CONSTEXPR14
bool operator()(
const value_type& element,
const K& key)
const ETL_NOEXCEPT
91 return kcompare(element.first, key);
95 ETL_CONSTEXPR14
bool operator()(
const key_type& key,
const value_type& element)
const ETL_NOEXCEPT
97 return kcompare(key, element.first);
102 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
103 ETL_CONSTEXPR14
bool operator()(
const K& key,
const value_type& element)
const ETL_NOEXCEPT
105 return kcompare(key, element.first);
108 key_compare kcompare;
124 ETL_CONSTEXPR14 const_iterator
begin() const ETL_NOEXCEPT
132 ETL_CONSTEXPR14 const_iterator
cbegin() const ETL_NOEXCEPT
140 ETL_CONSTEXPR14 const_iterator
end() const ETL_NOEXCEPT
142 return element_list_end;
148 ETL_CONSTEXPR14 const_iterator
cend() const ETL_NOEXCEPT
150 return element_list_end;
156 ETL_CONSTEXPR14 const_pointer
data() const ETL_NOEXCEPT
168 ETL_CONSTEXPR14
const mapped_type&
operator[](
const key_type& key)
const ETL_NOEXCEPT
170 const_iterator itr =
find(key);
183 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
184 ETL_CONSTEXPR14
const mapped_type&
operator[](
const K& key)
const ETL_NOEXCEPT
186 const_iterator itr =
find(key);
198 ETL_CONSTEXPR14
const mapped_type&
at(
const key_type& key)
const ETL_NOEXCEPT
200 const_iterator itr =
find(key);
213 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
214 ETL_CONSTEXPR14
const mapped_type&
at(
const K& key)
const ETL_NOEXCEPT
216 const_iterator itr =
find(key);
227 ETL_CONSTEXPR14 const_iterator
find(
const key_type& key)
const ETL_NOEXCEPT
231 if ((itr !=
end()) && (keys_are_equal(itr->first, key)))
246 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
247 ETL_CONSTEXPR14 const_iterator
find(
const K& key)
const ETL_NOEXCEPT
251 if ((itr !=
end()) && (keys_are_equal(itr->first, key)))
264 ETL_CONSTEXPR14
bool contains(
const key_type& key)
const ETL_NOEXCEPT
275 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
276 ETL_CONSTEXPR14
bool contains(
const K& key)
const ETL_NOEXCEPT
286 ETL_CONSTEXPR14 size_type
count(
const key_type& key)
const ETL_NOEXCEPT
297 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
298 ETL_CONSTEXPR14 size_type
count(
const K& key)
const ETL_NOEXCEPT
311 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const key_type& key)
const ETL_NOEXCEPT
313 return etl::equal_range(
begin(),
end(), key, vcompare);
325 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
326 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const ETL_NOEXCEPT
328 return etl::equal_range(
begin(),
end(), key, vcompare);
339 ETL_CONSTEXPR14 const_iterator
lower_bound(
const key_type& key)
const ETL_NOEXCEPT
341 return etl::lower_bound(
begin(),
end(), key, vcompare);
352 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
353 ETL_CONSTEXPR14 const_iterator
lower_bound(
const K& key)
const ETL_NOEXCEPT
355 return etl::lower_bound(
begin(),
end(), key, vcompare);
366 ETL_CONSTEXPR14 const_iterator
upper_bound(
const key_type& key)
const ETL_NOEXCEPT
368 return etl::upper_bound(
begin(),
end(), key, vcompare);
379 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
380 ETL_CONSTEXPR14 const_iterator
upper_bound(
const K& key)
const ETL_NOEXCEPT
382 return etl::upper_bound(
begin(),
end(), key, vcompare);
389 ETL_CONSTEXPR14 size_type
empty() const ETL_NOEXCEPT
398 ETL_CONSTEXPR14 size_type
full() const ETL_NOEXCEPT
400 return (max_elements != 0) && (
size() == max_elements);
407 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
409 return size_type(element_list_end - element_list);
416 ETL_CONSTEXPR14 size_type
max_size() const ETL_NOEXCEPT
426 ETL_CONSTEXPR14 size_type
capacity() const ETL_NOEXCEPT
435 ETL_CONSTEXPR14 key_compare
key_comp() const ETL_NOEXCEPT
437 return vcompare.kcompare;
454 template <
typename... TElements>
455 ETL_CONSTEXPR14
explicit iconst_map(
const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
456 : element_list(element_list_)
457 , element_list_end{element_list_ + size_}
458 , max_elements(max_elements_)
467 ETL_CONSTEXPR14
bool keys_are_equal(
const key_type& key1,
const key_type& key2)
const ETL_NOEXCEPT
469 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
476 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
477 ETL_CONSTEXPR14
bool keys_are_equal(
const K1& key1,
const K2& key2)
const ETL_NOEXCEPT
479 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
484 const value_type* element_list;
485 const value_type* element_list_end;
486 size_type max_elements;
492 template <
typename TKey,
typename TMapped,
size_t Size,
typename TKeyCompare = etl::less<TKey>>
499 using key_type =
typename base_t::key_type;
500 using value_type =
typename base_t::value_type;
501 using mapped_type =
typename base_t::mapped_type;
502 using key_compare =
typename base_t::key_compare;
503 using const_reference =
typename base_t::const_reference;
504 using const_pointer =
typename base_t::const_pointer;
505 using const_iterator =
typename base_t::const_iterator;
506 using size_type =
typename base_t::size_type;
508 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
509 static_assert((etl::is_default_constructible<mapped_type>::value),
"mapped_type must be default constructible");
517 template <
typename... TElements>
518 ETL_CONSTEXPR14
explicit const_map(TElements&&... elements) ETL_NOEXCEPT
520 , element_list{etl::forward<TElements>(elements)...}
522 static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value),
"All elements must be value_type");
523 static_assert(
sizeof...(elements) <= Size,
"Number of elements exceeds capacity");
528 value_type element_list[Size];
535 template <
typename... TElements>
537 ->
const_map<
typename etl::nth_type_t<0, TElements...>::first_type,
typename etl::nth_type_t<0, TElements...>::second_type,
sizeof...(TElements)>;
543 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey>>
550 using key_type =
typename base_t::key_type;
551 using value_type =
typename base_t::value_type;
552 using mapped_type =
typename base_t::mapped_type;
553 using key_compare =
typename base_t::key_compare;
554 using const_reference =
typename base_t::const_reference;
555 using const_pointer =
typename base_t::const_pointer;
556 using const_iterator =
typename base_t::const_iterator;
557 using size_type =
typename base_t::size_type;
559 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
560 static_assert((etl::is_default_constructible<mapped_type>::value),
"mapped_type must be default constructible");
566 :
iconst_map<TKey, TMapped, TKeyCompare>(
nullptr, 0, 0)
573 template <
size_type Size>
582 template <
size_type Size>
583 ETL_CONSTEXPR14
explicit const_map_ext(
const value_type (&begin_)[Size]) ETL_NOEXCEPT
593 template <
typename TElements,
size_t Size>
594 const_map_ext(
const etl::span<TElements, Size>&) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>;
596 template <
typename TElements,
size_t Size>
597 const_map_ext(
const TElements (&)[Size]) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>;
603 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
607 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
613 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
617 return !(lhs == rhs);
623 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
627 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
633 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
643 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
653 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
ETL_CONSTEXPR14 const_map_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT
Construct a const_map from an array.
Definition const_map.h:583
ETL_CONSTEXPR14 const_map_ext() ETL_NOEXCEPT
Default construct a const_map.
Definition const_map.h:565
ETL_CONSTEXPR14 const_map_ext(const etl::span< const value_type, Size > &sp) ETL_NOEXCEPT
Construct a const_map from a variadic list of elements.
Definition const_map.h:574
Map type designed for constexpr.
Definition const_map.h:494
ETL_CONSTEXPR14 const_map(TElements &&... elements) ETL_NOEXCEPT
Construct a const_map from a variadic list of elements. Static asserts if the elements are not of typ...
Definition const_map.h:518
How to compare elements and keys.
Definition const_map.h:71
Definition const_map.h:55
ETL_CONSTEXPR14 const mapped_type & operator[](const K &key) const ETL_NOEXCEPT
Key index operator. Enabled for transparent comparators.
Definition const_map.h:184
ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT
Definition const_map.h:398
ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT
Definition const_map.h:435
ETL_CONSTEXPR14 size_type count(const key_type &key) const ETL_NOEXCEPT
Counts the numbeer elements with key.
Definition const_map.h:286
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_map.h:366
ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT
Definition const_map.h:389
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_map.h:311
ETL_CONSTEXPR14 const_iterator end() const ETL_NOEXCEPT
Returns a const_iterator to the end of the map.
Definition const_map.h:140
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_map.h:380
ETL_CONSTEXPR14 const mapped_type & operator[](const key_type &key) const ETL_NOEXCEPT
Index operator.
Definition const_map.h:168
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_map.h:353
ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
Definition const_map.h:416
ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT
Definition const_map.h:116
ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT
Definition const_map.h:407
ETL_CONSTEXPR14 const_iterator find(const key_type &key) const ETL_NOEXCEPT
Gets a const_iterator to the mapped value at the key index.
Definition const_map.h:227
ETL_CONSTEXPR14 bool contains(const K &key) const ETL_NOEXCEPT
Checks if the map contains an element with key. Enabled if the comparator is transparent.
Definition const_map.h:276
ETL_CONSTEXPR14 iconst_map(const value_type *element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
Constructor.
Definition const_map.h:455
ETL_CONSTEXPR14 const_iterator cbegin() const ETL_NOEXCEPT
Returns a const_iterator to the beginning of the map.
Definition const_map.h:132
ETL_CONSTEXPR14 const_iterator cend() const ETL_NOEXCEPT
Returns a const_iterator to the end of the map.
Definition const_map.h:148
ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT
Definition const_map.h:444
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_map.h:326
ETL_CONSTEXPR14 bool contains(const key_type &key) const ETL_NOEXCEPT
Checks if the map contains an element with key.
Definition const_map.h:264
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_map.h:339
ETL_CONSTEXPR14 const_pointer data() const ETL_NOEXCEPT
Returns a const_pointer to the beginning of the map.
Definition const_map.h:156
ETL_CONSTEXPR14 const_iterator find(const K &key) const ETL_NOEXCEPT
Gets a const_iterator to the mapped value at the key index. Enabled if the comparator is transparent.
Definition const_map.h:247
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_map.h:298
ETL_CONSTEXPR14 const mapped_type & at(const key_type &key) const ETL_NOEXCEPT
Gets the mapped value at the key index.
Definition const_map.h:198
ETL_CONSTEXPR14 const_iterator begin() const ETL_NOEXCEPT
Returns a const_iterator to the beginning of the map.
Definition const_map.h:124
ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT
Definition const_map.h:426
ETL_CONSTEXPR14 const mapped_type & at(const K &key) const ETL_NOEXCEPT
Gets the mapped value at the key index. Enabled if the comparator is transparent.
Definition const_map.h:214
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