Embedded Template Library 1.0
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 "vector.h"
36#include "error_handler.h"
37#include "debug_count.h"
38#include "type_traits.h"
39#include "nth_type.h"
40#include "parameter_type.h"
41#include "exception.h"
42#include "static_assert.h"
43#include "iterator.h"
44#include "type_traits.h"
45#include "optional.h"
46
48
49#include <stddef.h>
50
51//*****************************************************************************
57//*****************************************************************************
58
59namespace etl
60{
61 //***************************************************************************
64 //***************************************************************************
66 {
67 public:
68
69 flat_map_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
70 : exception(reason_, file_name_, line_number_)
71 {
72 }
73 };
74
75 //***************************************************************************
78 //***************************************************************************
80 {
81 public:
82
83 flat_map_full(string_type file_name_, numeric_type line_number_)
84 : flat_map_exception(ETL_ERROR_TEXT("flat_map: full", ETL_REFERENCE_FLAT_MAP_FILE_ID"A"), file_name_, line_number_)
85 {
86 }
87 };
88
89 //***************************************************************************
92 //***************************************************************************
94 {
95 public:
96
97 flat_map_out_of_bounds(string_type file_name_, numeric_type line_number_)
98 : flat_map_exception(ETL_ERROR_TEXT("flat_map:bounds", ETL_REFERENCE_FLAT_MAP_FILE_ID"B"), file_name_, line_number_)
99 {
100 }
101 };
102
103 //***************************************************************************
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
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 }
143
144 iterator(typename lookup_t::iterator ilookup_)
145 : ilookup(ilookup_)
146 {
147 }
148
149 iterator(const iterator& other)
150 : ilookup(other.ilookup)
151 {
152 }
153
154 iterator& operator =(const iterator& other)
155 {
156 ilookup = other.ilookup;
157 return *this;
158 }
159
160 iterator& operator ++()
161 {
162 ++ilookup;
163 return *this;
164 }
165
166 iterator operator ++(int)
167 {
168 iterator temp(*this);
169 ++ilookup;
170 return temp;
171 }
172
173 iterator& operator --()
174 {
175 --ilookup;
176 return *this;
177 }
178
179 iterator operator --(int)
180 {
181 iterator temp(*this);
182 --ilookup;
183 return temp;
184 }
185
186 reference operator *() const
187 {
188 return *(*ilookup);
189 }
190
191 pointer operator &() const
192 {
193 return etl::addressof(*(*ilookup));
194 }
195
196 pointer operator ->() const
197 {
198 return etl::addressof(*(*ilookup));
199 }
200
201 friend bool operator == (const iterator& lhs, const iterator& rhs)
202 {
203 return lhs.ilookup == rhs.ilookup;
204 }
205
206 friend bool operator != (const iterator& lhs, const iterator& rhs)
207 {
208 return !(lhs == rhs);
209 }
210
211 private:
212
213 typename lookup_t::iterator ilookup;
214 };
215
216 //*************************************************************************
217 class const_iterator : public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, const value_type>
218 {
219 public:
220
221 friend class ireference_flat_map;
222
224 {
225 }
226
227 const_iterator(typename lookup_t::const_iterator ilookup_)
228 : ilookup(ilookup_)
229 {
230 }
231
232 const_iterator(const typename ireference_flat_map::iterator& other)
233 : ilookup(other.ilookup)
234 {
235 }
236
237 const_iterator(const const_iterator& other)
238 : ilookup(other.ilookup)
239 {
240 }
241
242 const_iterator& operator =(const typename ireference_flat_map::iterator& other)
243 {
244 ilookup = other.ilookup;
245 return *this;
246 }
247
248 const_iterator& operator =(const const_iterator& other)
249 {
250 ilookup = other.ilookup;
251 return *this;
252 }
253
254 const_iterator& operator ++()
255 {
256 ++ilookup;
257 return *this;
258 }
259
260 const_iterator operator ++(int)
261 {
262 const_iterator temp(*this);
263 ++ilookup;
264 return temp;
265 }
266
267 const_iterator& operator --()
268 {
269 --ilookup;
270 return *this;
271 }
272
273 const_iterator operator --(int)
274 {
275 const_iterator temp(*this);
276 --ilookup;
277 return temp;
278 }
279
280 const_reference operator *() const
281 {
282 return *(*ilookup);
283 }
284
285 const_pointer operator &() const
286 {
287 return etl::addressof(*(*ilookup));
288 }
289
290 const_pointer operator ->() const
291 {
292 return etl::addressof(*(*ilookup));
293 }
294
295 friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
296 {
297 return lhs.ilookup == rhs.ilookup;
298 }
299
300 friend bool operator != (const const_iterator& lhs, const const_iterator& rhs)
301 {
302 return !(lhs == rhs);
303 }
304
305 private:
306
307 typename lookup_t::const_iterator ilookup;
308 };
309
310 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
311 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
312 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
313
314 protected:
315
316 typedef const TKey& key_parameter_t;
317
318 private:
319
320 //*********************************************************************
322 //*********************************************************************
323 class Compare
324 {
325 public:
326
327 bool operator ()(const value_type& element, const key_type& key) const
328 {
329 return comp(element.first, key);
330 }
331
332 bool operator ()(const key_type& key, const value_type& element) const
333 {
334 return comp(key, element.first);
335 }
336
337#if ETL_USING_CPP11
338 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
339 bool operator ()(const value_type& element, const K& key) const
340 {
341 return comp(element.first, key);
342 }
343
344 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
345 bool operator ()(const K& key, const value_type& element) const
346 {
347 return comp(key, element.first);
348 }
349#endif
350
351 key_compare comp;
352 };
353
354 public:
355
356 //*********************************************************************
359 //*********************************************************************
361 {
362 return iterator(lookup.begin());
363 }
364
365 //*********************************************************************
368 //*********************************************************************
370 {
371 return const_iterator(lookup.begin());
372 }
373
374 //*********************************************************************
377 //*********************************************************************
379 {
380 return iterator(lookup.end());
381 }
382
383 //*********************************************************************
386 //*********************************************************************
388 {
389 return const_iterator(lookup.end());
390 }
391
392 //*********************************************************************
395 //*********************************************************************
397 {
398 return const_iterator(lookup.cbegin());
399 }
400
401 //*********************************************************************
404 //*********************************************************************
406 {
407 return const_iterator(lookup.cend());
408 }
409
410 //*********************************************************************
413 //*********************************************************************
414 reverse_iterator rbegin()
415 {
416 return reverse_iterator(lookup.rbegin());
417 }
418
419 //*********************************************************************
422 //*********************************************************************
423 const_reverse_iterator rbegin() const
424 {
425 return reverse_iterator(lookup.rbegin());
426 }
427
428 //*********************************************************************
431 //*********************************************************************
432 reverse_iterator rend()
433 {
434 return reverse_iterator(lookup.rend());
435 }
436
437 //*********************************************************************
440 //*********************************************************************
441 const_reverse_iterator rend() const
442 {
443 return const_reverse_iterator(lookup.rend());
444 }
445
446 //*********************************************************************
449 //*********************************************************************
450 const_reverse_iterator crbegin() const
451 {
452 return const_reverse_iterator(lookup.crbegin());
453 }
454
455 //*********************************************************************
458 //*********************************************************************
459 const_reverse_iterator crend() const
460 {
461 return const_reverse_iterator(lookup.crend());
462 }
463
464 //*********************************************************************
469 //*********************************************************************
470 mapped_type& at(key_parameter_t key)
471 {
472 iterator i_element = lower_bound(key);
473
474 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
475
476 return i_element->second;
477 }
478
479#if ETL_USING_CPP11
480 //*********************************************************************
481 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
482 mapped_type& at(const K& key)
483 {
484 iterator i_element = lower_bound(key);
485
486 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
487
488 return i_element->second;
489 }
490#endif
491
492 //*********************************************************************
497 //*********************************************************************
498 const mapped_type& at(key_parameter_t key) const
499 {
500 const_iterator i_element = lower_bound(key);
501
502 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
503
504 return i_element->second;
505 }
506
507#if ETL_USING_CPP11
508 //*********************************************************************
509 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
510 const mapped_type& at(const K& key) const
511 {
512 const_iterator i_element = lower_bound(key);
513
514 ETL_ASSERT((i_element != end()) && keys_are_equal(i_element->first, key), ETL_ERROR(flat_map_out_of_bounds));
515
516 return i_element->second;
517 }
518#endif
519
520 //*********************************************************************
526 //*********************************************************************
527 template <typename TIterator>
528 void assign(TIterator first, TIterator last)
529 {
530 ETL_STATIC_ASSERT((etl::is_same<value_type, typename etl::iterator_traits<TIterator>::value_type>::value), "Incompatible data for assign");
531
532#if ETL_IS_DEBUG_BUILD
533 difference_type d = etl::distance(first, last);
534 ETL_ASSERT(d <= difference_type(capacity()), ETL_ERROR(flat_map_full));
535#endif
536
537 clear();
538
539 while (first != last)
540 {
541 insert(*first);
542 ++first;
543 }
544 }
545
546 //*********************************************************************
550 //*********************************************************************
551 ETL_OR_STD::pair<iterator, bool> insert(reference value)
552 {
553 iterator i_element = lower_bound(value.first);
554
555 return insert_at(i_element, value);
556 }
557
558 //*********************************************************************
563 //*********************************************************************
564 iterator insert(const_iterator /*position*/, reference value)
565 {
566 return insert(value).first;
567 }
568
569 //*********************************************************************
575 //*********************************************************************
576 template <class TIterator>
577 void insert(TIterator first, TIterator last)
578 {
579 while (first != last)
580 {
581 insert(*first);
582 ++first;
583 }
584 }
585
586 //*********************************************************************
590 //*********************************************************************
591 size_t erase(key_parameter_t key)
592 {
593 iterator i_element = find(key);
594
595 if (i_element == end())
596 {
597 return 0U;
598 }
599 else
600 {
601 lookup.erase(i_element.ilookup);
602 return 1U;
603 }
604 }
605
606#if ETL_USING_CPP11
607 //*********************************************************************
608 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
609 size_t erase(K&& key)
610 {
611 iterator i_element = find(etl::forward<K>(key));
612
613 if (i_element == end())
614 {
615 return 0U;
616 }
617 else
618 {
619 lookup.erase(i_element.ilookup);
620 return 1U;
621 }
622 }
623#endif
624
625 //*********************************************************************
628 //*********************************************************************
630 {
631 return lookup.erase(i_element.ilookup);
632 }
633
634 //*********************************************************************
637 //*********************************************************************
639 {
640 return lookup.erase(i_element.ilookup);
641 }
642
643 //*********************************************************************
649 //*********************************************************************
651 {
652 return lookup.erase(first.ilookup, last.ilookup);
653 }
654
655 //*************************************************************************
657 //*************************************************************************
658 void clear()
659 {
660 lookup.clear();
661 }
662
663 //*********************************************************************
667 //*********************************************************************
668 iterator find(key_parameter_t key)
669 {
670 iterator itr = lower_bound(key);
671
672 if (itr != end())
673 {
674 if (keys_are_equal(itr->first, key))
675 {
676 return itr;
677 }
678 else
679 {
680 return end();
681 }
682 }
683
684 return end();
685 }
686
687#if ETL_USING_CPP11
688 //*********************************************************************
689 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
690 iterator find(const K& 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#endif
709
710 //*********************************************************************
714 //*********************************************************************
715 const_iterator find(key_parameter_t key) const
716 {
717 const_iterator itr = lower_bound(key);
718
719 if (itr != end())
720 {
721 if (keys_are_equal(itr->first, key))
722 {
723 return itr;
724 }
725 else
726 {
727 return end();
728 }
729 }
730
731 return end();
732 }
733
734#if ETL_USING_CPP11
735 //*********************************************************************
736 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
737 const_iterator find(const K& 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#endif
756
757 //*********************************************************************
761 //*********************************************************************
762 size_t count(key_parameter_t key) const
763 {
764 return (find(key) == end()) ? 0U : 1U;
765 }
766
767#if ETL_USING_CPP11
768 //*********************************************************************
769 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
770 size_t count(const K& key) const
771 {
772 return (find(key) == end()) ? 0U : 1U;
773 }
774#endif
775
776 //*********************************************************************
780 //*********************************************************************
781 iterator lower_bound(key_parameter_t key)
782 {
783 return etl::lower_bound(begin(), end(), key, compare);
784 }
785
786#if ETL_USING_CPP11
787 //*********************************************************************
788 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
789 iterator lower_bound(const K& key)
790 {
791 return etl::lower_bound(begin(), end(), key, compare);
792 }
793#endif
794
795 //*********************************************************************
799 //*********************************************************************
800 const_iterator lower_bound(key_parameter_t key) const
801 {
802 return etl::lower_bound(cbegin(), cend(), key, compare);
803 }
804
805#if ETL_USING_CPP11
806 //*********************************************************************
807 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
808 const_iterator lower_bound(const K& key) const
809 {
810 return etl::lower_bound(cbegin(), cend(), key, compare);
811 }
812#endif
813
814 //*********************************************************************
818 //*********************************************************************
819 iterator upper_bound(key_parameter_t key)
820 {
821 return etl::upper_bound(begin(), end(), key, compare);
822 }
823
824#if ETL_USING_CPP11
825 //*********************************************************************
826 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
827 iterator upper_bound(const K& key)
828 {
829 return etl::upper_bound(begin(), end(), key, compare);
830 }
831#endif
832
833 //*********************************************************************
837 //*********************************************************************
838 const_iterator upper_bound(key_parameter_t key) const
839 {
840 return etl::upper_bound(begin(), end(), key, compare);
841 }
842
843#if ETL_USING_CPP11
844 //*********************************************************************
845 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
846 const_iterator upper_bound(const K& key) const
847 {
848 return etl::upper_bound(begin(), end(), key, compare);
849 }
850#endif
851
852 //*********************************************************************
856 //*********************************************************************
857 ETL_OR_STD::pair<iterator, iterator> equal_range(key_parameter_t key)
858 {
859 iterator i_lower = etl::lower_bound(begin(), end(), key, compare);
860
861 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, end(), key, compare));
862 }
863
864#if ETL_USING_CPP11
865 //*********************************************************************
866 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
867 ETL_OR_STD::pair<iterator, iterator> equal_range(const K& 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#endif
874
875 //*********************************************************************
879 //*********************************************************************
880 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(key_parameter_t key) const
881 {
882 const_iterator i_lower = etl::lower_bound(cbegin(), cend(), key, compare);
883
884 return ETL_OR_STD::make_pair(i_lower, etl::upper_bound(i_lower, cend(), key, compare));
885 }
886
887#if ETL_USING_CPP11
888 //*********************************************************************
889 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
890 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(const K& 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#endif
897
898 //*************************************************************************
900 //*************************************************************************
901 bool contains(const TKey& key) const
902 {
903 return find(key) != end();
904 }
905
906#if ETL_USING_CPP11
907 //*************************************************************************
908 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
909 bool contains(const K& k) const
910 {
911 return find(k) != end();
912 }
913#endif
914
915 //*************************************************************************
918 //*************************************************************************
919 size_type size() const
920 {
921 return lookup.size();
922 }
923
924 //*************************************************************************
927 //*************************************************************************
928 bool empty() const
929 {
930 return lookup.empty();
931 }
932
933 //*************************************************************************
936 //*************************************************************************
937 bool full() const
938 {
939 return lookup.full();
940 }
941
942 //*************************************************************************
945 //*************************************************************************
946 size_type capacity() const
947 {
948 return lookup.capacity();
949 }
950
951 //*************************************************************************
954 //*************************************************************************
955 size_type max_size() const
956 {
957 return lookup.max_size();
958 }
959
960 //*************************************************************************
963 //*************************************************************************
964 size_t available() const
965 {
966 return lookup.available();
967 }
968
969 protected:
970
971 //*********************************************************************
973 //*********************************************************************
975 : lookup(lookup_)
976 {
977 }
978
979 //*********************************************************************
983 //*********************************************************************
984 ETL_OR_STD::pair<iterator, bool> insert_at(iterator i_element, value_type& value)
985 {
986 ETL_OR_STD::pair<iterator, bool> result(end(), false);
987
988 if (i_element == end())
989 {
990 // At the end.
991 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
992
993 lookup.push_back(&value);
994 result.first = --end();
995 result.second = true;
996 }
997 else
998 {
999 // Not at the end.
1000 result.first = i_element;
1001
1002 // Not an existing element?
1003 if (!keys_are_equal(i_element->first, value.first))
1004 {
1005 // A new one.
1006 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full));
1007 lookup.insert(i_element.ilookup, &value);
1008 result.second = true;
1009 }
1010 }
1011
1012 return result;
1013 }
1014
1015 //*********************************************************************
1017 //*********************************************************************
1018 bool keys_are_equal(key_parameter_t key1, key_parameter_t key2) const
1019 {
1020 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1021 }
1022
1023#if ETL_USING_CPP11
1024 //*********************************************************************
1025 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
1026 bool keys_are_equal(const K1& key1, const K2& key2) const
1027 {
1028 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
1029 }
1030#endif
1031
1032 private:
1033
1034 // Disable copy construction and assignment.
1036 ireference_flat_map& operator = (const ireference_flat_map&);
1037
1038 lookup_t& lookup;
1039
1040 Compare compare;
1041
1042 //*************************************************************************
1044 //*************************************************************************
1045#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
1046 public:
1047 virtual ~ireference_flat_map()
1048 {
1049 }
1050#else
1051 protected:
1053 {
1054 }
1055#endif
1056 };
1057
1058 //***************************************************************************
1064 //***************************************************************************
1065 template <typename TKey, typename TMapped, typename TKeyCompare>
1067 {
1068 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1069 }
1070
1071 //***************************************************************************
1077 //***************************************************************************
1078 template <typename TKey, typename TMapped, typename TKeyCompare>
1080 {
1081 return !(lhs == rhs);
1082 }
1083
1084 //***************************************************************************
1091 //***************************************************************************
1092 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = etl::less<TKey> >
1093 class reference_flat_map : public ireference_flat_map<TKey, TValue, TCompare>
1094 {
1095 public:
1096
1097 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1098
1099 //*************************************************************************
1101 //*************************************************************************
1103 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1104 {
1105 }
1106
1107 //*************************************************************************
1112 //*************************************************************************
1113 template <typename TIterator>
1114 reference_flat_map(TIterator first, TIterator last)
1115 : ireference_flat_map<TKey, TValue, TCompare>(lookup)
1116 {
1118 }
1119
1120 //*************************************************************************
1122 //*************************************************************************
1124 {
1126 }
1127
1128 //*************************************************************************
1130 //*************************************************************************
1132 {
1133 if (&rhs != this)
1134 {
1136 }
1137
1138 return *this;
1139 }
1140
1141 private:
1142
1144
1145 typedef typename ireference_flat_map<TKey, TValue, TCompare>::value_type node_t;
1146
1147 // The vector that stores pointers to the nodes.
1149 };
1150
1151 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare>
1152 ETL_CONSTANT size_t reference_flat_map< TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
1153
1154 //*************************************************************************
1156 //*************************************************************************
1157#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1158 template <typename... TPairs>
1159 reference_flat_map(TPairs...) -> reference_flat_map<typename etl::nth_type_t<0, TPairs...>::first_type,
1160 typename etl::nth_type_t<0, TPairs...>::second_type,
1161 sizeof...(TPairs)>;
1162#endif
1163
1164 //*************************************************************************
1166 //*************************************************************************
1167#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1168 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey>, typename... TPairs>
1169 constexpr auto make_reference_flat_map(TPairs&&... pairs) -> etl::reference_flat_map<TKey, TMapped, sizeof...(TPairs), TKeyCompare>
1170 {
1171 return { {etl::forward<TPairs>(pairs)...} };
1172 }
1173#endif
1174}
1175
1176#endif
Definition: reference_flat_map.h:218
Definition: reference_flat_map.h:134
#define ETL_ASSERT(b, e)
Definition: error_handler.h:316
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition: exception.h:69
Definition: exception.h:47
ETL_CONSTEXPR17 T * addressof(T &t)
Definition: addressof.h:51
mapped_type & at(key_parameter_t key)
Definition: reference_flat_map.h:470
iterator begin()
Definition: reference_flat_map.h:360
void clear()
Clears the reference_flat_map.
Definition: reference_flat_map.h:658
ETL_OR_STD::pair< iterator, bool > insert_at(iterator i_element, value_type &value)
Definition: reference_flat_map.h:984
const_reverse_iterator rbegin() const
Definition: reference_flat_map.h:423
~ireference_flat_map()
Destructor.
Definition: reference_flat_map.h:1052
const_iterator lower_bound(key_parameter_t key) const
Definition: reference_flat_map.h:800
const_reverse_iterator crbegin() const
Definition: reference_flat_map.h:450
reverse_iterator rend()
Definition: reference_flat_map.h:432
reference_flat_map()
Constructor.
Definition: reference_flat_map.h:1102
size_t count(key_parameter_t key) const
Definition: reference_flat_map.h:762
iterator end()
Definition: reference_flat_map.h:378
bool contains(const TKey &key) const
Check if the map contains the key.
Definition: reference_flat_map.h:901
const_iterator cbegin() const
Definition: reference_flat_map.h:396
ETL_OR_STD::pair< iterator, iterator > equal_range(key_parameter_t key)
Definition: reference_flat_map.h:857
size_t available() const
Definition: reference_flat_map.h:964
ireference_flat_map(lookup_t &lookup_)
Constructor.
Definition: reference_flat_map.h:974
const_reverse_iterator crend() const
Definition: reference_flat_map.h:459
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(key_parameter_t key) const
Definition: reference_flat_map.h:880
reference_flat_map & operator=(const reference_flat_map &rhs)
Assignment operator.
Definition: reference_flat_map.h:1131
reference_flat_map(TIterator first, TIterator last)
Definition: reference_flat_map.h:1114
size_type max_size() const
Definition: reference_flat_map.h:955
~reference_flat_map()
Destructor.
Definition: reference_flat_map.h:1123
iterator insert(const_iterator, reference value)
Definition: reference_flat_map.h:564
bool empty() const
Definition: reference_flat_map.h:928
const_iterator upper_bound(key_parameter_t key) const
Definition: reference_flat_map.h:838
const_iterator begin() const
Definition: reference_flat_map.h:369
iterator lower_bound(key_parameter_t key)
Definition: reference_flat_map.h:781
reverse_iterator rbegin()
Definition: reference_flat_map.h:414
iterator upper_bound(key_parameter_t key)
Definition: reference_flat_map.h:819
ETL_OR_STD::pair< iterator, bool > insert(reference value)
Definition: reference_flat_map.h:551
const_reverse_iterator rend() const
Definition: reference_flat_map.h:441
size_type size() const
Definition: reference_flat_map.h:919
iterator find(key_parameter_t key)
Definition: reference_flat_map.h:668
const_iterator cend() const
Definition: reference_flat_map.h:405
const_iterator find(key_parameter_t key) const
Definition: reference_flat_map.h:715
iterator erase(const_iterator first, const_iterator last)
Definition: reference_flat_map.h:650
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:1018
size_t erase(key_parameter_t key)
Definition: reference_flat_map.h:591
iterator erase(iterator i_element)
Definition: reference_flat_map.h:629
bool full() const
Definition: reference_flat_map.h:937
iterator erase(const_iterator i_element)
Definition: reference_flat_map.h:638
void assign(TIterator first, TIterator last)
Definition: reference_flat_map.h:528
size_type capacity() const
Definition: reference_flat_map.h:946
const mapped_type & at(key_parameter_t key) const
Definition: reference_flat_map.h:498
const_iterator end() const
Definition: reference_flat_map.h:387
void insert(TIterator first, TIterator last)
Definition: reference_flat_map.h:577
Definition: reference_flat_map.h:66
Definition: reference_flat_map.h:80
Definition: reference_flat_map.h:94
Definition: reference_flat_map.h:110
Definition: reference_flat_map.h:1094
bool operator==(const etl::ireference_flat_map< TKey, TMapped, TKeyCompare > &lhs, const etl::ireference_flat_map< TKey, TMapped, TKeyCompare > &rhs)
Definition: reference_flat_map.h:1066
bool operator!=(const etl::ireference_flat_map< TKey, TMapped, TKeyCompare > &lhs, const etl::ireference_flat_map< TKey, TMapped, TKeyCompare > &rhs)
Definition: reference_flat_map.h:1079
is_same
Definition: type_traits_generator.h:1041
iterator begin()
Definition: vector.h:100
size_type max_size() const
Definition: vector_base.h:140
void push_back(const_reference value)
Definition: vector.h:432
const_reverse_iterator crbegin() const
Definition: vector.h:190
reverse_iterator rend()
Definition: vector.h:172
size_type capacity() const
Definition: vector_base.h:131
const_iterator cend() const
Definition: vector.h:145
void clear()
Clears the vector.
Definition: vector.h:414
iterator end()
Definition: vector.h:118
const_reverse_iterator crend() const
Definition: vector.h:199
const_iterator cbegin() const
Definition: vector.h:136
bool full() const
Definition: vector.h:977
size_type size() const
Definition: vector.h:959
iterator erase(iterator i_element)
Definition: vector.h:865
bool empty() const
Definition: vector.h:968
size_t available() const
Definition: vector.h:986
reverse_iterator rbegin()
Definition: vector.h:154
iterator insert(const_iterator position, const_reference value)
Definition: vector.h:560
bitset_ext
Definition: absolute.h:38
pair< T1, T2 > make_pair(T1 a, T2 b)
A convenience wrapper for creating a pair from two objects.
Definition: utility.h:322
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition: byte.h:273
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
Definition: compare.h:52
iterator
Definition: iterator.h:399