Embedded Template Library 1.0
Loading...
Searching...
No Matches
flat_multimap.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) 2015 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_FLAT_MULTMAP_INCLUDED
32#define ETL_FLAT_MULTMAP_INCLUDED
33
34#include "platform.h"
35#include "initializer_list.h"
36#include "nth_type.h"
37#include "placement_new.h"
38#include "pool.h"
40#include "type_traits.h"
41#include "utility.h"
42
44
45//*****************************************************************************
51//*****************************************************************************
52
53namespace etl
54{
55 //***************************************************************************
60 //***************************************************************************
61 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey> >
62 class iflat_multimap : public etl::ireference_flat_multimap<TKey, TMapped, TKeyCompare>
63 {
64 public:
65
66 typedef ETL_OR_STD::pair<const TKey, TMapped> value_type;
67
68 private:
69
71 typedef typename refmap_t::lookup_t lookup_t;
72 typedef etl::ipool storage_t;
73
74 public:
75
76 typedef TKey key_type;
77 typedef TMapped mapped_type;
78 typedef TKeyCompare key_compare;
79 typedef value_type& reference;
80 typedef const value_type& const_reference;
81#if ETL_USING_CPP11
82 typedef value_type&& rvalue_reference;
83#endif
84 typedef value_type* pointer;
85 typedef const value_type* const_pointer;
86 typedef size_t size_type;
87
88 typedef const key_type& const_key_reference;
89#if ETL_USING_CPP11
90 typedef key_type&& rvalue_key_reference;
91#endif
92
93 typedef typename refmap_t::iterator iterator;
94 typedef typename refmap_t::const_iterator const_iterator;
95
96 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
97 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
98 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
99
100 private:
101
102 //*********************************************************************
104 //*********************************************************************
105 class compare
106 {
107 public:
108
109 bool operator()(const value_type& element, key_type key) const
110 {
111 return comp(element.first, key);
112 }
113
114 bool operator()(key_type key, const value_type& element) const
115 {
116 return comp(key, element.first);
117 }
118
119 key_compare comp;
120 };
121
122 public:
123
124 //*********************************************************************
127 //*********************************************************************
128 iterator begin()
129 {
130 return refmap_t::begin();
131 }
132
133 //*********************************************************************
136 //*********************************************************************
137 const_iterator begin() const
138 {
139 return refmap_t::begin();
140 }
141
142 //*********************************************************************
145 //*********************************************************************
146 iterator end()
147 {
148 return refmap_t::end();
149 }
150
151 //*********************************************************************
154 //*********************************************************************
155 const_iterator end() const
156 {
157 return refmap_t::end();
158 }
159
160 //*********************************************************************
163 //*********************************************************************
164 const_iterator cbegin() const
165 {
166 return refmap_t::cbegin();
167 }
168
169 //*********************************************************************
172 //*********************************************************************
173 const_iterator cend() const
174 {
175 return refmap_t::cend();
176 }
177
178 //*********************************************************************
182 //*********************************************************************
183 reverse_iterator rbegin()
184 {
185 return refmap_t::rbegin();
186 }
187
188 //*********************************************************************
192 //*********************************************************************
193 const_reverse_iterator rbegin() const
194 {
195 return refmap_t::rbegin();
196 }
197
198 //*********************************************************************
201 //*********************************************************************
202 reverse_iterator rend()
203 {
204 return refmap_t::rend();
205 }
206
207 //*********************************************************************
210 //*********************************************************************
211 const_reverse_iterator rend() const
212 {
213 return refmap_t::rend();
214 }
215
216 //*********************************************************************
221 //*********************************************************************
222 const_reverse_iterator crbegin() const
223 {
224 return refmap_t::crbegin();
225 }
226
227 //*********************************************************************
230 //*********************************************************************
231 const_reverse_iterator crend() const
232 {
233 return refmap_t::crend();
234 }
235
236 //*********************************************************************
243 //*********************************************************************
244 template <typename TIterator>
245 void assign(TIterator first, TIterator last)
246 {
247#if ETL_IS_DEBUG_BUILD
248 difference_type d = etl::distance(first, last);
249 ETL_ASSERT(d <= difference_type(capacity()), ETL_ERROR(flat_multimap_full));
250#endif
251
252 clear();
253
254 while (first != last)
255 {
256 insert(*first);
257 ++first;
258 }
259 }
260
261 //*********************************************************************
266 //*********************************************************************
267 ETL_OR_STD::pair<iterator, bool> insert(const value_type& value)
268 {
270
271 ETL_OR_STD::pair<iterator, bool> result(end(), false);
272
273 iterator i_element = upper_bound(value.first);
274
275 value_type* pvalue = storage.allocate<value_type>();
276 ::new (pvalue) value_type(value);
277 ETL_INCREMENT_DEBUG_COUNT;
278 result = refmap_t::insert_at(i_element, *pvalue);
279
280 return result;
281 }
282
283#if ETL_USING_CPP11
284 //*********************************************************************
289 //*********************************************************************
290 ETL_OR_STD::pair<iterator, bool> insert(rvalue_reference value)
291 {
293
294 ETL_OR_STD::pair<iterator, bool> result(end(), false);
295
296 iterator i_element = upper_bound(value.first);
297
298 value_type* pvalue = storage.allocate<value_type>();
299 ::new (pvalue) value_type(etl::move(value));
300 ETL_INCREMENT_DEBUG_COUNT;
301 result = refmap_t::insert_at(i_element, *pvalue);
302
303 return result;
304 }
305#endif
306
307 //*********************************************************************
313 //*********************************************************************
314 iterator insert(const_iterator /*position*/, const value_type& value)
315 {
316 return insert(value).first;
317 }
318
319#if ETL_USING_CPP11
320 //*********************************************************************
326 //*********************************************************************
327 iterator insert(const_iterator /*position*/, rvalue_reference value)
328 {
329 return insert(etl::move(value)).first;
330 }
331#endif
332
333 //*********************************************************************
340 //*********************************************************************
341 template <class TIterator>
342 void insert(TIterator first, TIterator last)
343 {
344 while (first != last)
345 {
346 insert(*first);
347 ++first;
348 }
349 }
350
351 //*************************************************************************
353 //*************************************************************************
354 ETL_OR_STD::pair<iterator, bool> emplace(const value_type& value)
355 {
356 return insert(value);
357 }
358
359 //*************************************************************************
361 //*************************************************************************
362 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, const mapped_type& mapped)
363 {
364 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
365
366 // Create it.
367 value_type* pvalue = storage.allocate<value_type>();
368 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
369 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(mapped);
370 iterator i_element = upper_bound(key);
371 ETL_INCREMENT_DEBUG_COUNT;
372
373 return refmap_t::insert_at(i_element, *pvalue);
374 }
375
376#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
377 //*************************************************************************
379 //*************************************************************************
380 template <typename... Args>
381 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, Args&&... args)
382 {
383 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
384
385 // Create it.
386 value_type* pvalue = storage.allocate<value_type>();
387 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
388 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(etl::forward<Args>(args)...);
389 iterator i_element = upper_bound(key);
390 ETL_INCREMENT_DEBUG_COUNT;
391
392 return refmap_t::insert_at(i_element, *pvalue);
393 }
394
395#else
396 //*************************************************************************
398 //*************************************************************************
399 template <typename T1>
400 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, const T1& value1)
401 {
402 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
403
404 // Create it.
405 value_type* pvalue = storage.allocate<value_type>();
406 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
407 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1);
408 iterator i_element = upper_bound(key);
409 ETL_INCREMENT_DEBUG_COUNT;
410
411 return refmap_t::insert_at(i_element, *pvalue);
412 }
413
414 //*************************************************************************
416 //*************************************************************************
417 template <typename T1, typename T2>
418 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2)
419 {
420 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
421
422 // Create it.
423 value_type* pvalue = storage.allocate<value_type>();
424 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
425 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2);
426 iterator i_element = upper_bound(key);
427 ETL_INCREMENT_DEBUG_COUNT;
428
429 return refmap_t::insert_at(i_element, *pvalue);
430 }
431
432 //*************************************************************************
434 //*************************************************************************
435 template <typename T1, typename T2, typename T3>
436 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3)
437 {
438 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
439
440 // Create it.
441 value_type* pvalue = storage.allocate<value_type>();
442 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
443 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2, value3);
444 iterator i_element = upper_bound(key);
445 ETL_INCREMENT_DEBUG_COUNT;
446
447 return refmap_t::insert_at(i_element, *pvalue);
448 }
449
450 //*************************************************************************
452 //*************************************************************************
453 template <typename T1, typename T2, typename T3, typename T4>
454 ETL_OR_STD::pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
455 {
456 ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
457
458 // Create it.
459 value_type* pvalue = storage.allocate<value_type>();
460 ::new ((void*)etl::addressof(pvalue->first)) key_type(key);
461 ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2, value3, value4);
462 iterator i_element = upper_bound(key);
463 ETL_INCREMENT_DEBUG_COUNT;
464
465 return refmap_t::insert_at(i_element, *pvalue);
466 }
467
468#endif
469
470 //*********************************************************************
474 //*********************************************************************
475 size_t erase(const_key_reference key)
476 {
477 ETL_OR_STD::pair<iterator, iterator> range = equal_range(key);
478
479 if (range.first == end())
480 {
481 return 0;
482 }
483 else
484 {
485 size_t d = static_cast<size_t>(etl::distance(range.first, range.second));
486 erase(range.first, range.second);
487 return d;
488 }
489 }
490
491#if ETL_USING_CPP11
492 //*********************************************************************
493 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
494 size_t erase(K&& key)
495 {
496 ETL_OR_STD::pair<iterator, iterator> range = equal_range(etl::forward<K>(key));
497
498 if (range.first == end())
499 {
500 return 0;
501 }
502 else
503 {
504 size_t d = static_cast<size_t>(etl::distance(range.first, range.second));
505 erase(range.first, range.second);
506 return d;
507 }
508 }
509#endif
510
511 //*********************************************************************
514 //*********************************************************************
515 iterator erase(iterator i_element)
516 {
517 i_element->~value_type();
518 storage.release(etl::addressof(*i_element));
519 ETL_DECREMENT_DEBUG_COUNT;
520 return refmap_t::erase(i_element);
521 }
522
523 //*********************************************************************
526 //*********************************************************************
527 iterator erase(const_iterator i_element)
528 {
529 i_element->~value_type();
530 storage.release(etl::addressof(*i_element));
531 ETL_DECREMENT_DEBUG_COUNT;
532 return refmap_t::erase(i_element);
533 }
534
535 //*********************************************************************
541 //*********************************************************************
542 iterator erase(const_iterator first, const_iterator last)
543 {
544 const_iterator itr = first;
545
546 while (itr != last)
547 {
548 itr->~value_type();
549 storage.release(etl::addressof(*itr));
550 ++itr;
551 ETL_DECREMENT_DEBUG_COUNT;
552 }
553
554 return refmap_t::erase(first, last);
555 }
556
557 //*************************************************************************
559 //*************************************************************************
560 void clear()
561 {
562 if ETL_IF_CONSTEXPR (etl::is_trivially_destructible<value_type>::value)
563 {
564 storage.release_all();
565 }
566 else
567 {
568 iterator itr = begin();
569
570 while (itr != end())
571 {
572 itr->~value_type();
573 storage.release(etl::addressof(*itr));
574 ++itr;
575 }
576 }
577
578 ETL_RESET_DEBUG_COUNT;
580 }
581
582 //*********************************************************************
586 //*********************************************************************
587 iterator find(const_key_reference key)
588 {
589 return refmap_t::find(key);
590 }
591
592#if ETL_USING_CPP11
593 //*********************************************************************
594 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
595 iterator find(const K& key)
596 {
597 return refmap_t::find(key);
598 }
599#endif
600
601 //*********************************************************************
605 //*********************************************************************
606 const_iterator find(const_key_reference key) const
607 {
608 return refmap_t::find(key);
609 }
610
611#if ETL_USING_CPP11
612 //*********************************************************************
613 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
614 const_iterator find(const K& key) const
615 {
616 return refmap_t::find(key);
617 }
618#endif
619
620 //*********************************************************************
624 //*********************************************************************
625 size_t count(const_key_reference key) const
626 {
627 return refmap_t::count(key);
628 }
629
630#if ETL_USING_CPP11
631 //*********************************************************************
632 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
633 size_t count(const K& key) const
634 {
635 return refmap_t::count(key);
636 }
637#endif
638
639 //*********************************************************************
643 //*********************************************************************
644 iterator lower_bound(const_key_reference key)
645 {
646 return refmap_t::lower_bound(key);
647 }
648
649#if ETL_USING_CPP11
650 //*********************************************************************
651 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
652 iterator lower_bound(const K& key)
653 {
654 return refmap_t::lower_bound(key);
655 }
656#endif
657
658 //*********************************************************************
662 //*********************************************************************
663 const_iterator lower_bound(const_key_reference key) const
664 {
665 return refmap_t::lower_bound(key);
666 }
667
668#if ETL_USING_CPP11
669 //*********************************************************************
670 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
671 const_iterator lower_bound(const K& key) const
672 {
673 return refmap_t::lower_bound(key);
674 }
675#endif
676
677 //*********************************************************************
681 //*********************************************************************
682 iterator upper_bound(const_key_reference key)
683 {
684 return refmap_t::upper_bound(key);
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 upper_bound(const K& key)
691 {
692 return refmap_t::upper_bound(key);
693 }
694#endif
695
696 //*********************************************************************
700 //*********************************************************************
701 const_iterator upper_bound(const_key_reference key) const
702 {
703 return refmap_t::upper_bound(key);
704 }
705
706#if ETL_USING_CPP11
707 //*********************************************************************
708 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
709 const_iterator upper_bound(const K& key) const
710 {
711 return refmap_t::upper_bound(key);
712 }
713#endif
714
715 //*********************************************************************
719 //*********************************************************************
720 ETL_OR_STD::pair<iterator, iterator> equal_range(const_key_reference key)
721 {
722 return refmap_t::equal_range(key);
723 }
724
725#if ETL_USING_CPP11
726 //*********************************************************************
727 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
728 ETL_OR_STD::pair<iterator, iterator> equal_range(const K& key)
729 {
730 return refmap_t::equal_range(key);
731 }
732#endif
733
734 //*********************************************************************
738 //*********************************************************************
739 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(const_key_reference key) const
740 {
741 return refmap_t::equal_range(key);
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 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(const K& key) const
748 {
749 return refmap_t::equal_range(key);
750 }
751#endif
752
753 //*************************************************************************
755 //*************************************************************************
756 bool contains(const_key_reference key) const
757 {
758 return find(key) != end();
759 }
760
761#if ETL_USING_CPP11
762 //*************************************************************************
763 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
764 bool contains(const K& k) const
765 {
766 return find(k) != end();
767 }
768#endif
769
770 //*************************************************************************
772 //*************************************************************************
774 {
775 if (&rhs != this)
776 {
777 assign(rhs.cbegin(), rhs.cend());
778 }
779
780 return *this;
781 }
782
783#if ETL_USING_CPP11
784 //*************************************************************************
786 //*************************************************************************
788 {
789 move_container(etl::move(rhs));
790
791 return *this;
792 }
793#endif
794
795 //*************************************************************************
798 //*************************************************************************
799 size_type size() const
800 {
801 return refmap_t::size();
802 }
803
804 //*************************************************************************
807 //*************************************************************************
808 bool empty() const
809 {
810 return refmap_t::empty();
811 }
812
813 //*************************************************************************
816 //*************************************************************************
817 bool full() const
818 {
819 return refmap_t::full();
820 }
821
822 //*************************************************************************
825 //*************************************************************************
826 size_type capacity() const
827 {
828 return refmap_t::capacity();
829 }
830
831 //*************************************************************************
834 //*************************************************************************
835 size_type max_size() const
836 {
837 return refmap_t::max_size();
838 }
839
840 //*************************************************************************
843 //*************************************************************************
844 size_t available() const
845 {
846 return refmap_t::available();
847 }
848
849 protected:
850
851 //*********************************************************************
853 //*********************************************************************
854 iflat_multimap(lookup_t& lookup_, storage_t& storage_)
855 : refmap_t(lookup_)
856 , storage(storage_)
857 {
858 }
859
860#if ETL_USING_CPP11
861 //*************************************************************************
864 //*************************************************************************
865 void move_container(iflat_multimap&& rhs)
866 {
867 if (&rhs != this)
868 {
869 this->clear();
870
871 etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator first = rhs.begin();
872 etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator last = rhs.end();
873
874 // Move all of the elements.
875 while (first != last)
876 {
877 typename etl::iflat_multimap<TKey, TMapped, TKeyCompare>::iterator temp = first;
878 ++temp;
879
880 this->insert(etl::move(*first));
881 first = temp;
882 }
883 }
884 }
885#endif
886
887 private:
888
889 // Disable copy construction.
891
892 storage_t& storage;
893
895 ETL_DECLARE_DEBUG_COUNT;
896
897 //*************************************************************************
899 //*************************************************************************
900#if defined(ETL_POLYMORPHIC_FLAT_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
901
902 public:
903
904 virtual ~iflat_multimap() {}
905#else
906
907 protected:
908
910#endif
911 };
912
913 //***************************************************************************
919 //***************************************************************************
920 template <typename TKey, typename TMapped, typename TKeyCompare>
922 {
923 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
924 }
925
926 //***************************************************************************
932 //***************************************************************************
933 template <typename TKey, typename TMapped, typename TKeyCompare>
938
939 //***************************************************************************
946 //***************************************************************************
947 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = etl::less<TKey> >
948 class flat_multimap : public etl::iflat_multimap<TKey, TValue, TCompare>
949 {
950 public:
951
952 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
953
954 //*************************************************************************
956 //*************************************************************************
958 : etl::iflat_multimap<TKey, TValue, TCompare>(lookup, storage)
959 {
960 }
961
962 //*************************************************************************
964 //*************************************************************************
966 : etl::iflat_multimap<TKey, TValue, TCompare>(lookup, storage)
967 {
968 this->assign(other.cbegin(), other.cend());
969 }
970
971#if ETL_USING_CPP11
972 //*************************************************************************
974 //*************************************************************************
976 : etl::iflat_multimap<TKey, TValue, TCompare>(lookup, storage)
977 {
978 if (&other != this)
979 {
980 this->move_container(etl::move(other));
981 }
982 }
983#endif
984
985 //*************************************************************************
990 //*************************************************************************
991 template <typename TIterator>
992 flat_multimap(TIterator first, TIterator last)
993 : etl::iflat_multimap<TKey, TValue, TCompare>(lookup, storage)
994 {
995 this->assign(first, last);
996 }
997
998#if ETL_HAS_INITIALIZER_LIST
999 //*************************************************************************
1001 //*************************************************************************
1002 flat_multimap(std::initializer_list< typename etl::iflat_multimap<TKey, TValue, TCompare>::value_type> init)
1003 : etl::iflat_multimap<TKey, TValue, TCompare>(lookup, storage)
1004 {
1005 this->assign(init.begin(), init.end());
1006 }
1007#endif
1008
1009 //*************************************************************************
1011 //*************************************************************************
1013 {
1014 this->clear();
1015 }
1016
1017 //*************************************************************************
1019 //*************************************************************************
1021 {
1022 if (&rhs != this)
1023 {
1024 this->assign(rhs.cbegin(), rhs.cend());
1025 }
1026
1027 return *this;
1028 }
1029
1030#if ETL_USING_CPP11
1031 //*************************************************************************
1033 //*************************************************************************
1034 flat_multimap& operator=(flat_multimap&& rhs)
1035 {
1036 if (&rhs != this)
1037 {
1038 this->move_container(etl::move(rhs));
1039 }
1040
1041 return *this;
1042 }
1043#endif
1044
1045 private:
1046
1047 typedef typename etl::iflat_multimap<TKey, TValue, TCompare>::value_type node_t;
1048
1049 // The pool of nodes.
1050 etl::pool<node_t, MAX_SIZE> storage;
1051
1052 // The vector that stores pointers to the nodes.
1053 etl::vector<node_t*, MAX_SIZE> lookup;
1054 };
1055
1056 template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare>
1057 ETL_CONSTANT size_t flat_multimap<TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
1058
1059 //*************************************************************************
1061 //*************************************************************************
1062#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1063 template <typename... TPairs>
1064 flat_multimap(TPairs...)
1065 -> flat_multimap<typename etl::nth_type_t<0, TPairs...>::first_type, typename etl::nth_type_t<0, TPairs...>::second_type, sizeof...(TPairs)>;
1066#endif
1067
1068 //*************************************************************************
1070 //*************************************************************************
1071#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1072 template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey>, typename... TPairs>
1073 constexpr auto make_flat_multimap(TPairs&&... pairs) -> etl::flat_multimap<TKey, TMapped, sizeof...(TPairs), TKeyCompare>
1074 {
1075 return {etl::forward<TPairs>(pairs)...};
1076 }
1077#endif
1078} // namespace etl
1079
1080#endif
Definition reference_flat_multimap.h:68
Definition reference_flat_multimap.h:85
const_reverse_iterator crbegin() const
Definition reference_flat_multimap.h:429
size_t count(key_parameter_t key) const
Definition reference_flat_multimap.h:696
ETL_OR_STD::pair< iterator, iterator > equal_range(key_parameter_t key)
Definition reference_flat_multimap.h:795
iterator lower_bound(key_parameter_t key)
Definition reference_flat_multimap.h:719
reverse_iterator rbegin()
Definition reference_flat_multimap.h:386
const_reverse_iterator crend() const
Definition reference_flat_multimap.h:440
iterator upper_bound(key_parameter_t key)
Definition reference_flat_multimap.h:757
bool empty() const
Definition reference_flat_multimap.h:866
const_iterator cbegin() const
Definition reference_flat_multimap.h:367
size_type size() const
Definition reference_flat_multimap.h:857
ETL_OR_STD::pair< iterator, bool > insert_at(iterator i_element, value_type &value)
Definition reference_flat_multimap.h:922
size_t available() const
Definition reference_flat_multimap.h:902
bool full() const
Definition reference_flat_multimap.h:875
size_t erase(key_parameter_t key)
Definition reference_flat_multimap.h:523
iterator begin()
Definition reference_flat_multimap.h:329
iterator end()
Definition reference_flat_multimap.h:348
iterator find(key_parameter_t key)
Definition reference_flat_multimap.h:602
const_iterator cend() const
Definition reference_flat_multimap.h:376
size_type max_size() const
Definition reference_flat_multimap.h:893
void clear()
Definition reference_flat_multimap.h:592
size_type capacity() const
Definition reference_flat_multimap.h:884
reverse_iterator rend()
Definition reference_flat_multimap.h:407
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
const_iterator begin() const
Definition flat_multimap.h:137
const_reverse_iterator crbegin() const
Definition flat_multimap.h:222
reverse_iterator rbegin()
Definition flat_multimap.h:183
iterator end()
Definition flat_multimap.h:146
flat_multimap & operator=(const flat_multimap &rhs)
Assignment operator.
Definition flat_multimap.h:1020
size_type capacity() const
Definition flat_multimap.h:826
size_type size() const
Definition flat_multimap.h:799
const_iterator cbegin() const
Definition flat_multimap.h:164
ETL_OR_STD::pair< iterator, bool > emplace(const key_type &key, const T1 &value1, const T2 &value2)
Emplaces a value to the map.
Definition flat_multimap.h:418
size_t available() const
Definition flat_multimap.h:844
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(const_key_reference key) const
Definition flat_multimap.h:739
flat_multimap(TIterator first, TIterator last)
Definition flat_multimap.h:992
const_reverse_iterator rbegin() const
Definition flat_multimap.h:193
bool full() const
Definition flat_multimap.h:817
const_iterator upper_bound(const_key_reference key) const
Definition flat_multimap.h:701
size_type max_size() const
Definition flat_multimap.h:835
size_t erase(const_key_reference key)
Definition flat_multimap.h:475
size_t count(const_key_reference key) const
Definition flat_multimap.h:625
const_reverse_iterator rend() const
Definition flat_multimap.h:211
iterator erase(const_iterator i_element)
Definition flat_multimap.h:527
iflat_multimap(lookup_t &lookup_, storage_t &storage_)
Constructor.
Definition flat_multimap.h:854
iterator insert(const_iterator, const value_type &value)
Definition flat_multimap.h:314
ETL_OR_STD::pair< iterator, bool > emplace(const value_type &value)
Emplaces a value to the map.
Definition flat_multimap.h:354
const_iterator end() const
Definition flat_multimap.h:155
iflat_multimap & operator=(const iflat_multimap &rhs)
Assignment operator.
Definition flat_multimap.h:773
flat_multimap()
Constructor.
Definition flat_multimap.h:957
const_reverse_iterator crend() const
Definition flat_multimap.h:231
ETL_OR_STD::pair< iterator, bool > emplace(const key_type &key, const mapped_type &mapped)
Emplaces a value to the map.
Definition flat_multimap.h:362
bool contains(const_key_reference key) const
Check if the map contains the key.
Definition flat_multimap.h:756
iterator begin()
Definition flat_multimap.h:128
const_iterator cend() const
Definition flat_multimap.h:173
void clear()
Clears the flat_multimap.
Definition flat_multimap.h:560
ETL_OR_STD::pair< iterator, bool > emplace(const key_type &key, const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Emplaces a value to the map.
Definition flat_multimap.h:454
reverse_iterator rend()
Definition flat_multimap.h:202
iterator erase(const_iterator first, const_iterator last)
Definition flat_multimap.h:542
~flat_multimap()
Destructor.
Definition flat_multimap.h:1012
ETL_OR_STD::pair< iterator, iterator > equal_range(const_key_reference key)
Definition flat_multimap.h:720
void assign(TIterator first, TIterator last)
Definition flat_multimap.h:245
iterator upper_bound(const_key_reference key)
Definition flat_multimap.h:682
ETL_OR_STD::pair< iterator, bool > emplace(const key_type &key, const T1 &value1, const T2 &value2, const T3 &value3)
Emplaces a value to the map.
Definition flat_multimap.h:436
ETL_OR_STD::pair< iterator, bool > insert(const value_type &value)
Definition flat_multimap.h:267
const_iterator find(const_key_reference key) const
Definition flat_multimap.h:606
const_iterator lower_bound(const_key_reference key) const
Definition flat_multimap.h:663
~iflat_multimap()
Destructor.
Definition flat_multimap.h:909
flat_multimap(const flat_multimap &other)
Copy constructor.
Definition flat_multimap.h:965
bool empty() const
Definition flat_multimap.h:808
void insert(TIterator first, TIterator last)
Definition flat_multimap.h:342
ETL_OR_STD::pair< iterator, bool > emplace(const key_type &key, const T1 &value1)
Emplaces a value to the map.
Definition flat_multimap.h:400
iterator find(const_key_reference key)
Definition flat_multimap.h:587
iterator lower_bound(const_key_reference key)
Definition flat_multimap.h:644
iterator erase(iterator i_element)
Definition flat_multimap.h:515
Definition flat_multimap.h:949
Definition flat_multimap.h:63
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
T * allocate()
Definition ipool.h:333
Definition ipool.h:109
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
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:997
iterator
Definition iterator.h:424