Embedded Template Library 1.0
Loading...
Searching...
No Matches
reference_flat_map.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2017 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_REFERENCE_FLAT_MAP_INCLUDED
32#define ETL_REFERENCE_FLAT_MAP_INCLUDED
33
34#include "platform.h"
35#include "debug_count.h"
36#include "error_handler.h"
37#include "exception.h"
38#include "iterator.h"
39#include "nth_type.h"
40#include "optional.h"
41#include "parameter_type.h"
42#include "static_assert.h"
43#include "type_traits.h"
44#include "vector.h"
45
47
48#include <stddef.h>
49
50//*****************************************************************************
56//*****************************************************************************
57
58namespace etl
59{
60 //***************************************************************************
63 //***************************************************************************
64 class flat_map_exception : public etl::exception
65 {
66 public:
67
68 flat_map_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
69 : exception(reason_, file_name_, line_number_)
70 {
71 }
72 };
73
74 //***************************************************************************
77 //***************************************************************************
78 class flat_map_full : public etl::flat_map_exception
79 {
80 public:
81
82 flat_map_full(string_type file_name_, numeric_type line_number_)
83 : flat_map_exception(ETL_ERROR_TEXT("flat_map: full", ETL_REFERENCE_FLAT_MAP_FILE_ID"A"), file_name_, line_number_)
84 {
85 }
86 };
87
88 //***************************************************************************
91 //***************************************************************************
92 class flat_map_out_of_bounds : public etl::flat_map_exception
93 {
94 public:
95
96 flat_map_out_of_bounds(string_type file_name_, numeric_type line_number_)
97 : flat_map_exception(ETL_ERROR_TEXT("flat_map:bounds", ETL_REFERENCE_FLAT_MAP_FILE_ID"B"), file_name_, line_number_)
98 {
99 }
100 };
101
102 //***************************************************************************
107 //***************************************************************************
108 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey> >
110 {
111 public:
112
113 typedef ETL_OR_STD::pair<const TKey, TMapped> value_type;
114
115 protected:
116
117 typedef etl::ivector<value_type*> lookup_t;
118
119 public:
120
121 typedef TKey key_type;
122 typedef TMapped mapped_type;
123 typedef TKeyCompare key_compare;
124 typedef value_type& reference;
125 typedef const value_type& const_reference;
126 typedef value_type* pointer;
127 typedef const value_type* const_pointer;
128 typedef size_t size_type;
129
130 class const_iterator;
131
132 //*************************************************************************
133 class iterator : public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, value_type>
134 {
135 public:
136
137 friend class ireference_flat_map;
139
140 iterator() {}
141
142 iterator(typename lookup_t::iterator ilookup_)
143 : ilookup(ilookup_)
144 {
145 }
146
147 iterator(const iterator& other)
148 : ilookup(other.ilookup)
149 {
150 }
151
152 iterator& operator=(const iterator& other)
153 {
154 ilookup = other.ilookup;
155 return *this;
156 }
157
158 iterator& operator++()
159 {
160 ++ilookup;
161 return *this;
162 }
163
164 iterator operator++(int)
165 {
166 iterator temp(*this);
167 ++ilookup;
168 return temp;
169 }
170
171 iterator& operator--()
172 {
173 --ilookup;
174 return *this;
175 }
176
177 iterator operator--(int)
178 {
179 iterator temp(*this);
180 --ilookup;
181 return temp;
182 }
183
184 reference operator*() const
185 {
186 return *(*ilookup);
187 }
188
189 pointer operator&() const
190 {
191 return etl::addressof(*(*ilookup));
192 }
193
194 pointer operator->() const
195 {
196 return etl::addressof(*(*ilookup));
197 }
198
199 friend bool operator==(const iterator& lhs, const iterator& rhs)
200 {
201 return lhs.ilookup == rhs.ilookup;
202 }
203
204 friend bool operator!=(const iterator& lhs, const iterator& rhs)
205 {
206 return !(lhs == rhs);
207 }
208
209 private:
210
211 typename lookup_t::iterator ilookup;
212 };
213
214 //*************************************************************************
215 class const_iterator : public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, const value_type>
216 {
217 public:
218
219 friend class ireference_flat_map;
220
221 const_iterator() {}
222
223 const_iterator(typename lookup_t::const_iterator ilookup_)
224 : ilookup(ilookup_)
225 {
226 }
227
228 const_iterator(const typename ireference_flat_map::iterator& other)
229 : ilookup(other.ilookup)
230 {
231 }
232
233 const_iterator(const const_iterator& other)
234 : ilookup(other.ilookup)
235 {
236 }
237
238 const_iterator& operator=(const typename ireference_flat_map::iterator& other)
239 {
240 ilookup = other.ilookup;
241 return *this;
242 }
243
244 const_iterator& operator=(const const_iterator& other)
245 {
246 ilookup = other.ilookup;
247 return *this;
248 }
249
250 const_iterator& operator++()
251 {
252 ++ilookup;
253 return *this;
254 }
255
256 const_iterator operator++(int)
257 {
258 const_iterator temp(*this);
259 ++ilookup;
260 return temp;
261 }
262
263 const_iterator& operator--()
264 {
265 --ilookup;
266 return *this;
267 }
268
269 const_iterator operator--(int)
270 {
271 const_iterator temp(*this);
272 --ilookup;
273 return temp;
274 }
275
276 const_reference operator*() const
277 {
278 return *(*ilookup);
279 }
280
281 const_pointer operator&() const
282 {
283 return etl::addressof(*(*ilookup));
284 }
285
286 const_pointer operator->() const
287 {
288 return etl::addressof(*(*ilookup));
289 }
290
291 friend bool operator==(const const_iterator& lhs, const const_iterator& rhs)
292 {
293 return lhs.ilookup == rhs.ilookup;
294 }
295
296 friend bool operator!=(const const_iterator& lhs, const const_iterator& rhs)
297 {
298 return !(lhs == rhs);
299 }
300
301 private:
302
303 typename lookup_t::const_iterator ilookup;
304 };
305
306 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
307 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
308 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
309
310 protected:
311
312 typedef const TKey& key_parameter_t;
313
314 private:
315
316 //*********************************************************************
318 //*********************************************************************
319 class Compare
320 {
321 public:
322
323 bool operator()(const value_type& element, const key_type& key) const
324 {
325 return comp(element.first, key);
326 }
327
328 bool operator()(const key_type& key, const value_type& element) const
329 {
330 return comp(key, element.first);
331 }
332
333#if ETL_USING_CPP11
334 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
335 bool operator()(const value_type& element, const K& key) const
336 {
337 return comp(element.first, key);
338 }
339
340 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
341 bool operator()(const K& key, const value_type& element) const
342 {
343 return comp(key, element.first);
344 }
345#endif
346
347 key_compare comp;
348 };
349
350 public:
351
352 //*********************************************************************
355 //*********************************************************************
356 iterator begin()
357 {
358 return iterator(lookup.begin());
359 }
360
361 //*********************************************************************
364 //*********************************************************************
365 const_iterator begin() const
366 {
367 return const_iterator(lookup.begin());
368 }
369
370 //*********************************************************************
373 //*********************************************************************
374 iterator end()
375 {
376 return iterator(lookup.end());
377 }
378
379 //*********************************************************************
382 //*********************************************************************
383 const_iterator end() const
384 {
385 return const_iterator(lookup.end());
386 }
387
388 //*********************************************************************
391 //*********************************************************************
392 const_iterator cbegin() const
393 {
394 return const_iterator(lookup.cbegin());
395 }
396
397 //*********************************************************************
400 //*********************************************************************
401 const_iterator cend() const
402 {
403 return const_iterator(lookup.cend());
404 }
405
406 //*********************************************************************
410 //*********************************************************************
411 reverse_iterator rbegin()
412 {
413 return reverse_iterator(lookup.rbegin());
414 }
415
416 //*********************************************************************
421 //*********************************************************************
422 const_reverse_iterator rbegin() const
423 {
424 return reverse_iterator(lookup.rbegin());
425 }
426
427 //*********************************************************************
430 //*********************************************************************
431 reverse_iterator rend()
432 {
433 return reverse_iterator(lookup.rend());
434 }
435
436 //*********************************************************************
440 //*********************************************************************
441 const_reverse_iterator rend() const
442 {
443 return const_reverse_iterator(lookup.rend());
444 }
445
446 //*********************************************************************
451 //*********************************************************************
452 const_reverse_iterator crbegin() const
453 {
454 return const_reverse_iterator(lookup.crbegin());
455 }
456
457 //*********************************************************************
461 //*********************************************************************
462 const_reverse_iterator crend() const
463 {
464 return const_reverse_iterator(lookup.crend());
465 }
466
467 //*********************************************************************
473 //*********************************************************************
474 mapped_type& at(key_parameter_t key)
475 {
476 iterator i_element = lower_bound(key);
477
478 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
479
480 return i_element->second;
481 }
482
483#if ETL_USING_CPP11
484 //*********************************************************************
485 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
486 mapped_type& at(const K& key)
487 {
488 iterator i_element = lower_bound(key);
489
490 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
491
492 return i_element->second;
493 }
494#endif
495
496 //*********************************************************************
502 //*********************************************************************
503 const mapped_type& at(key_parameter_t key) const
504 {
505 const_iterator i_element = lower_bound(key);
506
507 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
508
509 return i_element->second;
510 }
511
512#if ETL_USING_CPP11
513 //*********************************************************************
514 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
515 const mapped_type& at(const K& key) const
516 {
517 const_iterator i_element = lower_bound(key);
518
519 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
520
521 return i_element->second;
522 }
523#endif
524
525 //*********************************************************************
533 //*********************************************************************
534 template <typename TIterator>
535 void assign(TIterator first, TIterator last)
536 {
537 ETL_STATIC_ASSERT((etl::is_same<value_type, typename etl::iterator_traits< TIterator>::value_type>::value), "Incompatible data for assign");
538
539#if ETL_IS_DEBUG_BUILD
540 difference_type d = etl::distance(first, last);
541 ETL_ASSERT(d <= difference_type(capacity()), ETL_ERROR(flat_map_full));
542#endif
543
544 clear();
545
546 while (first != last)
547 {
548 insert(*first);
549 ++first;
550 }
551 }
552
553 //*********************************************************************
558 //*********************************************************************
559 ETL_OR_STD::pair<iterator, bool> insert(reference value)
560 {
561 iterator i_element = lower_bound(value.first);
562
563 return insert_at(i_element, value);
564 }
565
566 //*********************************************************************
572 //*********************************************************************
573 iterator insert(const_iterator /*position*/, reference value)
574 {
575 return insert(value).first;
576 }
577
578 //*********************************************************************
585 //*********************************************************************
586 template <class TIterator>
587 void insert(TIterator first, TIterator last)
588 {
589 while (first != last)
590 {
591 insert(*first);
592 ++first;
593 }
594 }
595
596 //*********************************************************************
600 //*********************************************************************
601 size_t erase(key_parameter_t key)
602 {
603 iterator i_element = find(key);
604
605 if (i_element == end())
606 {
607 return 0U;
608 }
609 else
610 {
611 lookup.erase(i_element.ilookup);
612 return 1U;
613 }
614 }
615
616#if ETL_USING_CPP11
617 //*********************************************************************
618 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
619 size_t erase(K&& key)
620 {
621 iterator i_element = find(etl::forward<K>(key));
622
623 if (i_element == end())
624 {
625 return 0U;
626 }
627 else
628 {
629 lookup.erase(i_element.ilookup);
630 return 1U;
631 }
632 }
633#endif
634
635 //*********************************************************************
638 //*********************************************************************
639 iterator erase(iterator i_element)
640 {
641 return lookup.erase(i_element.ilookup);
642 }
643
644 //*********************************************************************
647 //*********************************************************************
648 iterator erase(const_iterator i_element)
649 {
650 return lookup.erase(i_element.ilookup);
651 }
652
653 //*********************************************************************
659 //*********************************************************************
660 iterator erase(const_iterator first, const_iterator last)
661 {
662 return lookup.erase(first.ilookup, last.ilookup);
663 }
664
665 //*************************************************************************
667 //*************************************************************************
668 void clear()
669 {
670 lookup.clear();
671 }
672
673 //*********************************************************************
677 //*********************************************************************
678 iterator find(key_parameter_t key)
679 {
680 iterator itr = lower_bound(key);
681
682 if (itr != end())
683 {
684 if (keys_are_equal(itr->first, key))
685 {
686 return itr;
687 }
688 else
689 {
690 return end();
691 }
692 }
693
694 return end();
695 }
696
697#if ETL_USING_CPP11
698 //*********************************************************************
699 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
700 iterator find(const K& key)
701 {
702 iterator itr = lower_bound(key);
703
704 if (itr != end())
705 {
706 if (keys_are_equal(itr->first, key))
707 {
708 return itr;
709 }
710 else
711 {
712 return end();
713 }
714 }
715
716 return end();
717 }
718#endif
719
720 //*********************************************************************
724 //*********************************************************************
725 const_iterator find(key_parameter_t key) const
726 {
727 const_iterator itr = lower_bound(key);
728
729 if (itr != end())
730 {
731 if (keys_are_equal(itr->first, key))
732 {
733 return itr;
734 }
735 else
736 {
737 return end();
738 }
739 }
740
741 return end();
742 }
743
744#if ETL_USING_CPP11
745 //*********************************************************************
746 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
747 const_iterator find(const K& key) const
748 {
749 const_iterator itr = lower_bound(key);
750
751 if (itr != end())
752 {
753 if (keys_are_equal(itr->first, key))
754 {
755 return itr;
756 }
757 else
758 {
759 return end();
760 }
761 }
762
763 return end();
764 }
765#endif
766
767 //*********************************************************************
771 //*********************************************************************
772 size_t count(key_parameter_t key) const
773 {
774 return (find(key) == end()) ? 0U : 1U;
775 }
776
777#if ETL_USING_CPP11
778 //*********************************************************************
779 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
780 size_t count(const K& key) const
781 {
782 return (find(key) == end()) ? 0U : 1U;
783 }
784#endif
785
786 //*********************************************************************
790 //*********************************************************************
791 iterator lower_bound(key_parameter_t key)
792 {
793 return etl::lower_bound(begin(), end(), key, compare);
794 }
795
796#if ETL_USING_CPP11
797 //*********************************************************************
798 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
799 iterator lower_bound(const K& key)
800 {
801 return etl::lower_bound(begin(), end(), key, compare);
802 }
803#endif
804
805 //*********************************************************************
809 //*********************************************************************
810 const_iterator lower_bound(key_parameter_t key) const
811 {
812 return etl::lower_bound(cbegin(), cend(), key, compare);
813 }
814
815#if ETL_USING_CPP11
816 //*********************************************************************
817 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
818 const_iterator lower_bound(const K& key) const
819 {
820 return etl::lower_bound(cbegin(), cend(), key, compare);
821 }
822#endif
823
824 //*********************************************************************
828 //*********************************************************************
829 iterator upper_bound(key_parameter_t key)
830 {
831 return etl::upper_bound(begin(), end(), key, compare);
832 }
833
834#if ETL_USING_CPP11
835 //*********************************************************************
836 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
837 iterator upper_bound(const K& key)
838 {
839 return etl::upper_bound(begin(), end(), key, compare);
840 }
841#endif
842
843 //*********************************************************************
847 //*********************************************************************
848 const_iterator upper_bound(key_parameter_t key) const
849 {
850 return etl::upper_bound(begin(), end(), key, compare);
851 }
852
853#if ETL_USING_CPP11
854 //*********************************************************************
855 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
856 const_iterator upper_bound(const K& key) const
857 {
858 return etl::upper_bound(begin(), end(), key, compare);
859 }
860#endif
861
862 //*********************************************************************
866 //*********************************************************************
867 ETL_OR_STD::pair<iterator, iterator> equal_range(key_parameter_t key)
868 {
869 iterator i_lower = etl::lower_bound(begin(), end(), key, compare);
870
871 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, end(), key, compare));
872 }
873
874#if ETL_USING_CPP11
875 //*********************************************************************
876 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
877 ETL_OR_STD::pair<iterator, iterator> equal_range(const K& key)
878 {
879 iterator i_lower = etl::lower_bound(begin(), end(), key, compare);
880
881 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, end(), key, compare));
882 }
883#endif
884
885 //*********************************************************************
889 //*********************************************************************
890 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(key_parameter_t key) const
891 {
892 const_iterator i_lower = etl::lower_bound(cbegin(), cend(), key, compare);
893
894 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, cend(), key, compare));
895 }
896
897#if ETL_USING_CPP11
898 //*********************************************************************
899 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
900 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(const K& key) const
901 {
902 const_iterator i_lower = etl::lower_bound(cbegin(), cend(), key, compare);
903
904 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, cend(), key, compare));
905 }
906#endif
907
908 //*************************************************************************
910 //*************************************************************************
911 bool contains(const TKey& key) const
912 {
913 return find(key) != end();
914 }
915
916#if ETL_USING_CPP11
917 //*************************************************************************
918 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
919 bool contains(const K& k) const
920 {
921 return find(k) != end();
922 }
923#endif
924
925 //*************************************************************************
928 //*************************************************************************
929 size_type size() const
930 {
931 return lookup.size();
932 }
933
934 //*************************************************************************
937 //*************************************************************************
938 bool empty() const
939 {
940 return lookup.empty();
941 }
942
943 //*************************************************************************
946 //*************************************************************************
947 bool full() const
948 {
949 return lookup.full();
950 }
951
952 //*************************************************************************
955 //*************************************************************************
956 size_type capacity() const
957 {
958 return lookup.capacity();
959 }
960
961 //*************************************************************************
964 //*************************************************************************
965 size_type max_size() const
966 {
967 return lookup.max_size();
968 }
969
970 //*************************************************************************
973 //*************************************************************************
974 size_t available() const
975 {
976 return lookup.available();
977 }
978
979 protected:
980
981 //*********************************************************************
983 //*********************************************************************
984 ireference_flat_map(lookup_t& lookup_)
985 : lookup(lookup_)
986 {
987 }
988
989 //*********************************************************************
993 //*********************************************************************
994 ETL_OR_STD::pair<iterator, bool> insert_at(iterator i_element, value_type& value)
995 {
996 ETL_OR_STD::pair<iterator, bool> result(end(), false);
997
998 if (i_element == end())
999 {
1000 // At the end.
1001 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
1002
1003 lookup.push_back(&value);
1004 result.first = --end();
1005 result.second = true;
1006 }
1007 else
1008 {
1009 // Not at the end.
1010 result.first = i_element;
1011
1012 // Not an existing element?
1013 if (!keys_are_equal(i_element->first, value.first))
1014 {
1015 // A new one.
1016 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
1017 lookup.insert(i_element.ilookup, &value);
1018 result.second = true;
1019 }
1020 }
1021
1022 return result;
1023 }
1024
1025 //*********************************************************************
1027 //*********************************************************************
1028 bool keys_are_equal(key_parameter_t key1, key_parameter_t key2) const
1029 {
1030 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1031 }
1032
1033#if ETL_USING_CPP11
1034 //*********************************************************************
1035 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
1036 bool keys_are_equal(const K1& key1, const K2& key2) const
1037 {
1038 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1039 }
1040#endif
1041
1042 private:
1043
1044 // Disable copy construction and assignment.
1046 ireference_flat_map& operator=(const ireference_flat_map&);
1047
1048 lookup_t& lookup;
1049
1050 Compare compare;
1051
1052 //*************************************************************************
1054 //*************************************************************************
1055#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
1056
1057 public:
1058
1059 virtual ~ireference_flat_map() {}
1060#else
1061
1062 protected:
1063
1065#endif
1066 };
1067
1068 //***************************************************************************
1074 //***************************************************************************
1075 template <typename TKey, typename TMapped, typename TKeyCompare>
1077 {
1078 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1079 }
1080
1081 //***************************************************************************
1087 //***************************************************************************
1088 template <typename TKey, typename TMapped, typename TKeyCompare>
1093
1094 //***************************************************************************
1101 //***************************************************************************
1102 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = etl::less<TKey> >
1103 class reference_flat_map : public ireference_flat_map<TKey, TValue, TCompare>
1104 {
1105 public:
1106
1107 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1108
1109 //*************************************************************************
1111 //*************************************************************************
1113 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1114 {
1115 }
1116
1117 //*************************************************************************
1122 //*************************************************************************
1123 template <typename TIterator>
1124 reference_flat_map(TIterator first, TIterator last)
1125 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1126 {
1128 }
1129
1130 //*************************************************************************
1132 //*************************************************************************
1137
1138 //*************************************************************************
1140 //*************************************************************************
1142 {
1143 if (&rhs != this)
1144 {
1146 }
1147
1148 return *this;
1149 }
1150
1151 private:
1152
1154
1155 typedef typename ireference_flat_map<TKey, TValue, TCompare>::value_type node_t;
1156
1157 // The vector that stores pointers to the nodes.
1159 };
1160
1161 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare>
1162 ETL_CONSTANT size_t reference_flat_map< TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
1163
1164 //*************************************************************************
1166 //*************************************************************************
1167#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1168 template <typename... TPairs>
1169 reference_flat_map(TPairs...)
1170 -> reference_flat_map<typename etl::nth_type_t<0, TPairs...>::first_type, typename etl::nth_type_t<0, TPairs...>::second_type, sizeof...(TPairs)>;
1171#endif
1172
1173 //*************************************************************************
1175 //*************************************************************************
1176#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1177 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey>, typename... TPairs>
1178 constexpr auto make_reference_flat_map(TPairs&&... pairs) -> etl::reference_flat_map<TKey, TMapped, sizeof...(TPairs), TKeyCompare>
1179 {
1180 return {etl::forward<TPairs>(pairs)...};
1181 }
1182#endif
1183} // namespace etl
1184
1185#endif
Definition reference_flat_map.h:216
Definition reference_flat_map.h:134
ETL_CONSTEXPR14 bool operator!=(const etl::bitset< Active_Bits, TElement > &lhs, const etl::bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:2529
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition exception.h:59
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
mapped_type & at(key_parameter_t key)
Definition reference_flat_map.h:474
iterator begin()
Definition reference_flat_map.h:356
void clear()
Clears the reference_flat_map.
Definition reference_flat_map.h:668
ETL_OR_STD::pair< iterator, bool > insert_at(iterator i_element, value_type &value)
Definition reference_flat_map.h:994
const_reverse_iterator rbegin() const
Definition reference_flat_map.h:422
~ireference_flat_map()
Destructor.
Definition reference_flat_map.h:1064
const_iterator lower_bound(key_parameter_t key) const
Definition reference_flat_map.h:810
const_reverse_iterator crbegin() const
Definition reference_flat_map.h:452
reverse_iterator rend()
Definition reference_flat_map.h:431
reference_flat_map()
Constructor.
Definition reference_flat_map.h:1112
size_t count(key_parameter_t key) const
Definition reference_flat_map.h:772
iterator end()
Definition reference_flat_map.h:374
bool contains(const TKey &key) const
Check if the map contains the key.
Definition reference_flat_map.h:911
const_iterator cbegin() const
Definition reference_flat_map.h:392
ETL_OR_STD::pair< iterator, iterator > equal_range(key_parameter_t key)
Definition reference_flat_map.h:867
size_t available() const
Definition reference_flat_map.h:974
ireference_flat_map(lookup_t &lookup_)
Constructor.
Definition reference_flat_map.h:984
const_reverse_iterator crend() const
Definition reference_flat_map.h:462
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(key_parameter_t key) const
Definition reference_flat_map.h:890
reference_flat_map & operator=(const reference_flat_map &rhs)
Assignment operator.
Definition reference_flat_map.h:1141
reference_flat_map(TIterator first, TIterator last)
Definition reference_flat_map.h:1124
size_type max_size() const
Definition reference_flat_map.h:965
~reference_flat_map()
Destructor.
Definition reference_flat_map.h:1133
iterator insert(const_iterator, reference value)
Definition reference_flat_map.h:573
bool empty() const
Definition reference_flat_map.h:938
const_iterator upper_bound(key_parameter_t key) const
Definition reference_flat_map.h:848
const_iterator begin() const
Definition reference_flat_map.h:365
iterator lower_bound(key_parameter_t key)
Definition reference_flat_map.h:791
reverse_iterator rbegin()
Definition reference_flat_map.h:411
iterator upper_bound(key_parameter_t key)
Definition reference_flat_map.h:829
ETL_OR_STD::pair< iterator, bool > insert(reference value)
Definition reference_flat_map.h:559
const_reverse_iterator rend() const
Definition reference_flat_map.h:441
size_type size() const
Definition reference_flat_map.h:929
iterator find(key_parameter_t key)
Definition reference_flat_map.h:678
const_iterator cend() const
Definition reference_flat_map.h:401
const_iterator find(key_parameter_t key) const
Definition reference_flat_map.h:725
iterator erase(const_iterator first, const_iterator last)
Definition reference_flat_map.h:660
bool keys_are_equal(key_parameter_t key1, key_parameter_t key2) const
Check to see if the keys are equal.
Definition reference_flat_map.h:1028
size_t erase(key_parameter_t key)
Definition reference_flat_map.h:601
iterator erase(iterator i_element)
Definition reference_flat_map.h:639
bool full() const
Definition reference_flat_map.h:947
iterator erase(const_iterator i_element)
Definition reference_flat_map.h:648
void assign(TIterator first, TIterator last)
Definition reference_flat_map.h:535
size_type capacity() const
Definition reference_flat_map.h:956
const mapped_type & at(key_parameter_t key) const
Definition reference_flat_map.h:503
const_iterator end() const
Definition reference_flat_map.h:383
void insert(TIterator first, TIterator last)
Definition reference_flat_map.h:587
Definition reference_flat_map.h:65
Definition reference_flat_map.h:79
Definition reference_flat_map.h:93
Definition reference_flat_map.h:110
Definition reference_flat_map.h:1104
iterator erase(iterator i_element)
Definition vector.h:911
Definition vector.h:71
Definition vector.h:1277
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
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1093
Definition compare.h:51
iterator
Definition iterator.h:424