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 ETL_OR_STD::pair<iterator, bool> emplace(reference value)
574 {
575 return insert(value);
576 }
577
578 //*********************************************************************
584 //*********************************************************************
585 iterator insert(const_iterator /*position*/, reference value)
586 {
587 return insert(value).first;
588 }
589
590 //*********************************************************************
597 //*********************************************************************
598 template <class TIterator>
599 void insert(TIterator first, TIterator last)
600 {
601 while (first != last)
602 {
603 insert(*first);
604 ++first;
605 }
606 }
607
608 //*********************************************************************
612 //*********************************************************************
613 size_t erase(key_parameter_t key)
614 {
615 iterator i_element = find(key);
616
617 if (i_element == end())
618 {
619 return 0U;
620 }
621 else
622 {
623 lookup.erase(i_element.ilookup);
624 return 1U;
625 }
626 }
627
628#if ETL_USING_CPP11
629 //*********************************************************************
630 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
631 size_t erase(K&& key)
632 {
633 iterator i_element = find(etl::forward<K>(key));
634
635 if (i_element == end())
636 {
637 return 0U;
638 }
639 else
640 {
641 lookup.erase(i_element.ilookup);
642 return 1U;
643 }
644 }
645#endif
646
647 //*********************************************************************
650 //*********************************************************************
651 iterator erase(iterator i_element)
652 {
653 return lookup.erase(i_element.ilookup);
654 }
655
656 //*********************************************************************
659 //*********************************************************************
660 iterator erase(const_iterator i_element)
661 {
662 return lookup.erase(i_element.ilookup);
663 }
664
665 //*********************************************************************
671 //*********************************************************************
672 iterator erase(const_iterator first, const_iterator last)
673 {
674 return lookup.erase(first.ilookup, last.ilookup);
675 }
676
677 //*************************************************************************
679 //*************************************************************************
680 void clear()
681 {
682 lookup.clear();
683 }
684
685 //*********************************************************************
689 //*********************************************************************
690 iterator find(key_parameter_t key)
691 {
692 iterator itr = lower_bound(key);
693
694 if (itr != end())
695 {
696 if (keys_are_equal(itr->first, key))
697 {
698 return itr;
699 }
700 else
701 {
702 return end();
703 }
704 }
705
706 return end();
707 }
708
709#if ETL_USING_CPP11
710 //*********************************************************************
711 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
712 iterator find(const K& key)
713 {
714 iterator itr = lower_bound(key);
715
716 if (itr != end())
717 {
718 if (keys_are_equal(itr->first, key))
719 {
720 return itr;
721 }
722 else
723 {
724 return end();
725 }
726 }
727
728 return end();
729 }
730#endif
731
732 //*********************************************************************
736 //*********************************************************************
737 const_iterator find(key_parameter_t key) const
738 {
739 const_iterator itr = lower_bound(key);
740
741 if (itr != end())
742 {
743 if (keys_are_equal(itr->first, key))
744 {
745 return itr;
746 }
747 else
748 {
749 return end();
750 }
751 }
752
753 return end();
754 }
755
756#if ETL_USING_CPP11
757 //*********************************************************************
758 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
759 const_iterator find(const K& key) const
760 {
761 const_iterator itr = lower_bound(key);
762
763 if (itr != end())
764 {
765 if (keys_are_equal(itr->first, key))
766 {
767 return itr;
768 }
769 else
770 {
771 return end();
772 }
773 }
774
775 return end();
776 }
777#endif
778
779 //*********************************************************************
783 //*********************************************************************
784 size_t count(key_parameter_t key) const
785 {
786 return (find(key) == end()) ? 0U : 1U;
787 }
788
789#if ETL_USING_CPP11
790 //*********************************************************************
791 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
792 size_t count(const K& key) const
793 {
794 return (find(key) == end()) ? 0U : 1U;
795 }
796#endif
797
798 //*********************************************************************
802 //*********************************************************************
803 iterator lower_bound(key_parameter_t key)
804 {
805 return etl::lower_bound(begin(), end(), key, compare);
806 }
807
808#if ETL_USING_CPP11
809 //*********************************************************************
810 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
811 iterator lower_bound(const K& key)
812 {
813 return etl::lower_bound(begin(), end(), key, compare);
814 }
815#endif
816
817 //*********************************************************************
821 //*********************************************************************
822 const_iterator lower_bound(key_parameter_t key) const
823 {
824 return etl::lower_bound(cbegin(), cend(), key, compare);
825 }
826
827#if ETL_USING_CPP11
828 //*********************************************************************
829 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
830 const_iterator lower_bound(const K& key) const
831 {
832 return etl::lower_bound(cbegin(), cend(), key, compare);
833 }
834#endif
835
836 //*********************************************************************
840 //*********************************************************************
841 iterator upper_bound(key_parameter_t key)
842 {
843 return etl::upper_bound(begin(), end(), key, compare);
844 }
845
846#if ETL_USING_CPP11
847 //*********************************************************************
848 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
849 iterator upper_bound(const K& key)
850 {
851 return etl::upper_bound(begin(), end(), key, compare);
852 }
853#endif
854
855 //*********************************************************************
859 //*********************************************************************
860 const_iterator upper_bound(key_parameter_t key) const
861 {
862 return etl::upper_bound(begin(), end(), key, compare);
863 }
864
865#if ETL_USING_CPP11
866 //*********************************************************************
867 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
868 const_iterator upper_bound(const K& key) const
869 {
870 return etl::upper_bound(begin(), end(), key, compare);
871 }
872#endif
873
874 //*********************************************************************
878 //*********************************************************************
879 ETL_OR_STD::pair<iterator, iterator> equal_range(key_parameter_t key)
880 {
881 iterator i_lower = etl::lower_bound(begin(), end(), key, compare);
882
883 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, end(), key, compare));
884 }
885
886#if ETL_USING_CPP11
887 //*********************************************************************
888 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
889 ETL_OR_STD::pair<iterator, iterator> equal_range(const K& key)
890 {
891 iterator i_lower = etl::lower_bound(begin(), end(), key, compare);
892
893 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, end(), key, compare));
894 }
895#endif
896
897 //*********************************************************************
901 //*********************************************************************
902 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(key_parameter_t key) const
903 {
904 const_iterator i_lower = etl::lower_bound(cbegin(), cend(), key, compare);
905
906 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, cend(), key, compare));
907 }
908
909#if ETL_USING_CPP11
910 //*********************************************************************
911 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
912 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(const K& key) const
913 {
914 const_iterator i_lower = etl::lower_bound(cbegin(), cend(), key, compare);
915
916 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, cend(), key, compare));
917 }
918#endif
919
920 //*************************************************************************
922 //*************************************************************************
923 bool contains(const TKey& key) const
924 {
925 return find(key) != end();
926 }
927
928#if ETL_USING_CPP11
929 //*************************************************************************
930 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
931 bool contains(const K& k) const
932 {
933 return find(k) != end();
934 }
935#endif
936
937 //*************************************************************************
940 //*************************************************************************
941 size_type size() const
942 {
943 return lookup.size();
944 }
945
946 //*************************************************************************
949 //*************************************************************************
950 bool empty() const
951 {
952 return lookup.empty();
953 }
954
955 //*************************************************************************
958 //*************************************************************************
959 bool full() const
960 {
961 return lookup.full();
962 }
963
964 //*************************************************************************
967 //*************************************************************************
968 size_type capacity() const
969 {
970 return lookup.capacity();
971 }
972
973 //*************************************************************************
976 //*************************************************************************
977 size_type max_size() const
978 {
979 return lookup.max_size();
980 }
981
982 //*************************************************************************
985 //*************************************************************************
986 size_t available() const
987 {
988 return lookup.available();
989 }
990
991 protected:
992
993 //*********************************************************************
995 //*********************************************************************
996 ireference_flat_map(lookup_t& lookup_)
997 : lookup(lookup_)
998 {
999 }
1000
1001 //*********************************************************************
1005 //*********************************************************************
1006 ETL_OR_STD::pair<iterator, bool> insert_at(iterator i_element, value_type& value)
1007 {
1008 ETL_OR_STD::pair<iterator, bool> result(end(), false);
1009
1010 if (i_element == end())
1011 {
1012 // At the end.
1013 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
1014
1015 lookup.push_back(&value);
1016 result.first = --end();
1017 result.second = true;
1018 }
1019 else
1020 {
1021 // Not at the end.
1022 result.first = i_element;
1023
1024 // Not an existing element?
1025 if (!keys_are_equal(i_element->first, value.first))
1026 {
1027 // A new one.
1028 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
1029 lookup.insert(i_element.ilookup, &value);
1030 result.second = true;
1031 }
1032 }
1033
1034 return result;
1035 }
1036
1037 //*********************************************************************
1039 //*********************************************************************
1040 bool keys_are_equal(key_parameter_t key1, key_parameter_t key2) const
1041 {
1042 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1043 }
1044
1045#if ETL_USING_CPP11
1046 //*********************************************************************
1047 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
1048 bool keys_are_equal(const K1& key1, const K2& key2) const
1049 {
1050 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1051 }
1052#endif
1053
1054 private:
1055
1056 // Disable copy construction and assignment.
1058 ireference_flat_map& operator=(const ireference_flat_map&);
1059
1060 lookup_t& lookup;
1061
1062 Compare compare;
1063
1064 //*************************************************************************
1066 //*************************************************************************
1067#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
1068
1069 public:
1070
1071 virtual ~ireference_flat_map() {}
1072#else
1073
1074 protected:
1075
1077#endif
1078 };
1079
1080 //***************************************************************************
1086 //***************************************************************************
1087 template <typename TKey, typename TMapped, typename TKeyCompare>
1089 {
1090 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1091 }
1092
1093 //***************************************************************************
1099 //***************************************************************************
1100 template <typename TKey, typename TMapped, typename TKeyCompare>
1105
1106 //***************************************************************************
1113 //***************************************************************************
1114 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = etl::less<TKey> >
1115 class reference_flat_map : public ireference_flat_map<TKey, TValue, TCompare>
1116 {
1117 public:
1118
1119 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1120
1121 //*************************************************************************
1123 //*************************************************************************
1125 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1126 {
1127 }
1128
1129 //*************************************************************************
1134 //*************************************************************************
1135 template <typename TIterator>
1136 reference_flat_map(TIterator first, TIterator last)
1137 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1138 {
1140 }
1141
1142 //*************************************************************************
1144 //*************************************************************************
1149
1150 //*************************************************************************
1152 //*************************************************************************
1154 {
1155 if (&rhs != this)
1156 {
1158 }
1159
1160 return *this;
1161 }
1162
1163 private:
1164
1166
1167 typedef typename ireference_flat_map<TKey, TValue, TCompare>::value_type node_t;
1168
1169 // The vector that stores pointers to the nodes.
1171 };
1172
1173 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare>
1174 ETL_CONSTANT size_t reference_flat_map< TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
1175
1176 //*************************************************************************
1178 //*************************************************************************
1179#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1180 template <typename... TPairs>
1181 reference_flat_map(TPairs...)
1182 -> reference_flat_map<typename etl::nth_type_t<0, TPairs...>::first_type, typename etl::nth_type_t<0, TPairs...>::second_type, sizeof...(TPairs)>;
1183#endif
1184
1185 //*************************************************************************
1187 //*************************************************************************
1188#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1189 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey>, typename... TPairs>
1190 constexpr auto make_reference_flat_map(TPairs&&... pairs) -> etl::reference_flat_map<TKey, TMapped, sizeof...(TPairs), TKeyCompare>
1191 {
1192 return {etl::forward<TPairs>(pairs)...};
1193 }
1194#endif
1195} // namespace etl
1196
1197#endif
Definition reference_flat_map.h:216
Definition reference_flat_map.h:134
Definition vector.h:65
#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:680
ETL_OR_STD::pair< iterator, bool > insert_at(iterator i_element, value_type &value)
Definition reference_flat_map.h:1006
const_reverse_iterator rbegin() const
Definition reference_flat_map.h:422
~ireference_flat_map()
Destructor.
Definition reference_flat_map.h:1076
const_iterator lower_bound(key_parameter_t key) const
Definition reference_flat_map.h:822
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:1124
size_t count(key_parameter_t key) const
Definition reference_flat_map.h:784
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:923
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:879
size_t available() const
Definition reference_flat_map.h:986
ireference_flat_map(lookup_t &lookup_)
Constructor.
Definition reference_flat_map.h:996
ETL_OR_STD::pair< iterator, bool > emplace(reference value)
Definition reference_flat_map.h:573
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:902
reference_flat_map & operator=(const reference_flat_map &rhs)
Assignment operator.
Definition reference_flat_map.h:1153
reference_flat_map(TIterator first, TIterator last)
Definition reference_flat_map.h:1136
size_type max_size() const
Definition reference_flat_map.h:977
~reference_flat_map()
Destructor.
Definition reference_flat_map.h:1145
iterator insert(const_iterator, reference value)
Definition reference_flat_map.h:585
bool empty() const
Definition reference_flat_map.h:950
const_iterator upper_bound(key_parameter_t key) const
Definition reference_flat_map.h:860
const_iterator begin() const
Definition reference_flat_map.h:365
iterator lower_bound(key_parameter_t key)
Definition reference_flat_map.h:803
reverse_iterator rbegin()
Definition reference_flat_map.h:411
iterator upper_bound(key_parameter_t key)
Definition reference_flat_map.h:841
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:941
iterator find(key_parameter_t key)
Definition reference_flat_map.h:690
const_iterator cend() const
Definition reference_flat_map.h:401
const_iterator find(key_parameter_t key) const
Definition reference_flat_map.h:737
iterator erase(const_iterator first, const_iterator last)
Definition reference_flat_map.h:672
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:1040
size_t erase(key_parameter_t key)
Definition reference_flat_map.h:613
iterator erase(iterator i_element)
Definition reference_flat_map.h:651
bool full() const
Definition reference_flat_map.h:959
iterator erase(const_iterator i_element)
Definition reference_flat_map.h:660
void assign(TIterator first, TIterator last)
Definition reference_flat_map.h:535
size_type capacity() const
Definition reference_flat_map.h:968
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:599
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:1116
Definition vector.h:1830
Definition absolute.h:40
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
Definition compare.h:51
iterator
Definition iterator.h:482
ETL_CONSTEXPR14 bool operator==(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Equality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:903
ETL_CONSTEXPR14 bool operator!=(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Inequality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:937