Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
reference_flat_set.h
00001 ///\file 00002 00003 /****************************************************************************** 00004 The MIT License(MIT) 00005 00006 Embedded Template Library. 00007 https://github.com/ETLCPP/etl 00008 http://www.etlcpp.com 00009 00010 Copyright(c) 2017 jwellbelove 00011 00012 Permission is hereby granted, free of charge, to any person obtaining a copy 00013 of this software and associated documentation files(the "Software"), to deal 00014 in the Software without restriction, including without limitation the rights 00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 00016 copies of the Software, and to permit persons to whom the Software is 00017 furnished to do so, subject to the following conditions : 00018 00019 The above copyright notice and this permission notice shall be included in all 00020 copies or substantial portions of the Software. 00021 00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00028 SOFTWARE. 00029 ******************************************************************************/ 00030 00031 #ifndef __ETL_REFERENCE_FLAT_SET__ 00032 #define __ETL_REFERENCE_FLAT_SET__ 00033 00034 #include <iterator> 00035 #include <algorithm> 00036 #include <functional> 00037 #include <utility> 00038 #include <stddef.h> 00039 00040 #include "platform.h " 00041 #include "type_traits.h " 00042 #include "pool.h " 00043 #include "error_handler.h " 00044 #include "exception.h " 00045 #include "vector.h " 00046 00047 #undef ETL_FILE 00048 #define ETL_FILE "32" 00049 00050 namespace etl 00051 { 00052 //*************************************************************************** 00053 ///\ingroup reference_flat_set 00054 /// Exception base for flat_sets 00055 //*************************************************************************** 00056 class flat_set_exception : public exception 00057 { 00058 public: 00059 00060 flat_set_exception(string_type reason_, string_type file_name_, numeric_type line_number_) 00061 : exception(reason_, file_name_, line_number_) 00062 { 00063 } 00064 }; 00065 00066 //*************************************************************************** 00067 ///\ingroup reference_flat_set 00068 /// Vector full exception. 00069 //*************************************************************************** 00070 class flat_set_full : public flat_set_exception 00071 { 00072 public: 00073 00074 flat_set_full(string_type file_name_, numeric_type line_number_) 00075 : flat_set_exception(ETL_ERROR_TEXT("flat_set:full", ETL_FILE"A"), file_name_, line_number_) 00076 { 00077 } 00078 }; 00079 00080 //*************************************************************************** 00081 ///\ingroup reference_flat_set 00082 /// Vector iterator exception. 00083 //*************************************************************************** 00084 class flat_set_iterator : public flat_set_exception 00085 { 00086 public: 00087 00088 flat_set_iterator(string_type file_name_, numeric_type line_number_) 00089 : flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_FILE"C"), file_name_, line_number_) 00090 { 00091 } 00092 }; 00093 00094 //*************************************************************************** 00095 /// The base class for specifically sized reference_flat_sets. 00096 /// Can be used as a reference type for all reference_flat_sets containing a specific type. 00097 ///\ingroup reference_flat_set 00098 //*************************************************************************** 00099 template <typename T, typename TKeyCompare = std::less<T> > 00100 class ireference_flat_set 00101 { 00102 public: 00103 00104 typedef T key_type; 00105 typedef T value_type; 00106 typedef TKeyCompare key_compare; 00107 typedef value_type& reference; 00108 typedef const value_type& const_reference; 00109 typedef value_type* pointer; 00110 typedef const value_type* const_pointer; 00111 typedef size_t size_type; 00112 00113 protected: 00114 00115 typedef etl::ivector<value_type*> lookup_t ; 00116 00117 public: 00118 00119 //************************************************************************* 00120 class iterator : public std::iterator<std::bidirectional_iterator_tag, value_type> 00121 { 00122 public: 00123 00124 friend class ireference_flat_set; 00125 00126 iterator() 00127 { 00128 } 00129 00130 iterator(typename lookup_t::iterator ilookup_) 00131 : ilookup(ilookup_) 00132 { 00133 } 00134 00135 iterator(const iterator& other) 00136 : ilookup(other.ilookup) 00137 { 00138 } 00139 00140 iterator& operator =(const iterator& other) 00141 { 00142 ilookup = other.ilookup; 00143 return *this; 00144 } 00145 00146 iterator& operator ++() 00147 { 00148 ++ilookup; 00149 return *this; 00150 } 00151 00152 iterator operator ++(int) 00153 { 00154 iterator temp(*this); 00155 ++ilookup; 00156 return temp; 00157 } 00158 00159 iterator& operator --() 00160 { 00161 --ilookup; 00162 return *this; 00163 } 00164 00165 iterator operator --(int) 00166 { 00167 iterator temp(*this); 00168 --ilookup; 00169 return temp; 00170 } 00171 00172 reference operator *() 00173 { 00174 return *(*ilookup); 00175 } 00176 00177 const_reference operator *() const 00178 { 00179 return *(*ilookup); 00180 } 00181 00182 pointer operator &() 00183 { 00184 return etl::addressof(*(*ilookup)); 00185 } 00186 00187 const_pointer operator &() const 00188 { 00189 return &(*(*ilookup)); 00190 } 00191 00192 pointer operator ->() 00193 { 00194 return etl::addressof(*(*ilookup)); 00195 } 00196 00197 const_pointer operator ->() const 00198 { 00199 return etl::addressof(*(*ilookup)); 00200 } 00201 00202 friend bool operator == (const iterator& lhs, const iterator& rhs) 00203 { 00204 return lhs.ilookup == rhs.ilookup; 00205 } 00206 00207 friend bool operator != (const iterator& lhs, const iterator& rhs) 00208 { 00209 return !(lhs == rhs); 00210 } 00211 00212 private: 00213 00214 typename lookup_t::iterator ilookup; 00215 }; 00216 00217 //************************************************************************* 00218 class const_iterator : public std::iterator<std::bidirectional_iterator_tag, const value_type> 00219 { 00220 public: 00221 00222 friend class ireference_flat_set; 00223 00224 const_iterator() 00225 { 00226 } 00227 00228 const_iterator(typename lookup_t::const_iterator ilookup_) 00229 : ilookup(ilookup_) 00230 { 00231 } 00232 00233 const_iterator(const iterator& other) 00234 : ilookup(other.ilookup) 00235 { 00236 } 00237 00238 const_iterator(const const_iterator& other) 00239 : ilookup(other.ilookup) 00240 { 00241 } 00242 00243 const_iterator& operator =(const iterator& other) 00244 { 00245 ilookup = other.ilookup; 00246 return *this; 00247 } 00248 00249 const_iterator& operator =(const const_iterator& other) 00250 { 00251 ilookup = other.ilookup; 00252 return *this; 00253 } 00254 00255 const_iterator& operator ++() 00256 { 00257 ++ilookup; 00258 return *this; 00259 } 00260 00261 const_iterator operator ++(int) 00262 { 00263 const_iterator temp(*this); 00264 ++ilookup; 00265 return temp; 00266 } 00267 00268 const_iterator& operator --() 00269 { 00270 --ilookup; 00271 return *this; 00272 } 00273 00274 const_iterator operator --(int) 00275 { 00276 const_iterator temp(*this); 00277 --ilookup; 00278 return temp; 00279 } 00280 00281 const_reference operator *() const 00282 { 00283 return *(*ilookup); 00284 } 00285 00286 const_pointer operator &() const 00287 { 00288 return etl::addressof(*(*ilookup)); 00289 } 00290 00291 const_pointer operator ->() const 00292 { 00293 return etl::addressof(*(*ilookup)); 00294 } 00295 00296 friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) 00297 { 00298 return lhs.ilookup == rhs.ilookup; 00299 } 00300 00301 friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) 00302 { 00303 return !(lhs == rhs); 00304 } 00305 00306 private: 00307 00308 typename lookup_t::const_iterator ilookup; 00309 }; 00310 00311 protected: 00312 00313 typedef typename etl::parameter_type<T>::type parameter_t; 00314 00315 public: 00316 00317 typedef std::reverse_iterator<iterator> reverse_iterator; 00318 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00319 typedef typename std::iterator_traits<iterator>::difference_type difference_type; 00320 00321 //********************************************************************* 00322 /// Returns an iterator to the beginning of the reference_flat_set. 00323 ///\return An iterator to the beginning of the reference_flat_set. 00324 //********************************************************************* 00325 iterator begin() 00326 { 00327 return iterator(lookup.begin()); 00328 } 00329 00330 //********************************************************************* 00331 /// Returns a const_iterator to the beginning of the reference_flat_set. 00332 ///\return A const iterator to the beginning of the reference_flat_set. 00333 //********************************************************************* 00334 const_iterator begin() const 00335 { 00336 return const_iterator(lookup.begin()); 00337 } 00338 00339 //********************************************************************* 00340 /// Returns an iterator to the end of the reference_flat_set. 00341 ///\return An iterator to the end of the reference_flat_set. 00342 //********************************************************************* 00343 iterator end() 00344 { 00345 return iterator(lookup.end()); 00346 } 00347 00348 //********************************************************************* 00349 /// Returns a const_iterator to the end of the reference_flat_set. 00350 ///\return A const iterator to the end of the reference_flat_set. 00351 //********************************************************************* 00352 const_iterator end() const 00353 { 00354 return const_iterator(lookup.end()); 00355 } 00356 00357 //********************************************************************* 00358 /// Returns a const_iterator to the beginning of the reference_flat_set. 00359 ///\return A const iterator to the beginning of the reference_flat_set. 00360 //********************************************************************* 00361 const_iterator cbegin() const 00362 { 00363 return const_iterator(lookup.cbegin()); 00364 } 00365 00366 //********************************************************************* 00367 /// Returns a const_iterator to the end of the reference_flat_set. 00368 ///\return A const iterator to the end of the reference_flat_set. 00369 //********************************************************************* 00370 const_iterator cend() const 00371 { 00372 return const_iterator(lookup.cend()); 00373 } 00374 00375 //********************************************************************* 00376 /// Returns an reverse iterator to the reverse beginning of the reference_flat_set. 00377 ///\return Iterator to the reverse beginning of the reference_flat_set. 00378 //********************************************************************* 00379 reverse_iterator rbegin() 00380 { 00381 return reverse_iterator(lookup.rbegin()); 00382 } 00383 00384 //********************************************************************* 00385 /// Returns a const reverse iterator to the reverse beginning of the reference_flat_set. 00386 ///\return Const iterator to the reverse beginning of the reference_flat_set. 00387 //********************************************************************* 00388 const_reverse_iterator rbegin() const 00389 { 00390 return const_reverse_iterator(lookup.rbegin()); 00391 } 00392 00393 //********************************************************************* 00394 /// Returns a reverse iterator to the end + 1 of the reference_flat_set. 00395 ///\return Reverse iterator to the end + 1 of the reference_flat_set. 00396 //********************************************************************* 00397 reverse_iterator rend() 00398 { 00399 return reverse_iterator(lookup.rend()); 00400 } 00401 00402 //********************************************************************* 00403 /// Returns a const reverse iterator to the end + 1 of the reference_flat_set. 00404 ///\return Const reverse iterator to the end + 1 of the reference_flat_set. 00405 //********************************************************************* 00406 const_reverse_iterator rend() const 00407 { 00408 return const_reverse_iterator(lookup.rend()); 00409 } 00410 00411 //********************************************************************* 00412 /// Returns a const reverse iterator to the reverse beginning of the reference_flat_set. 00413 ///\return Const reverse iterator to the reverse beginning of the reference_flat_set. 00414 //********************************************************************* 00415 const_reverse_iterator crbegin() const 00416 { 00417 return const_reverse_iterator(lookup.crbegin()); 00418 } 00419 00420 //********************************************************************* 00421 /// Returns a const reverse iterator to the end + 1 of the reference_flat_set. 00422 ///\return Const reverse iterator to the end + 1 of the reference_flat_set. 00423 //********************************************************************* 00424 const_reverse_iterator crend() const 00425 { 00426 return const_reverse_iterator(lookup.crend()); 00427 } 00428 00429 //********************************************************************* 00430 /// Assigns values to the reference_flat_set. 00431 /// If asserts or exceptions are enabled, emits reference_flat_set_full if the reference_flat_set does not have enough free space. 00432 /// If asserts or exceptions are enabled, emits reference_flat_set_iterator if the iterators are reversed. 00433 ///\param first The iterator to the first element. 00434 ///\param last The iterator to the last element + 1. 00435 //********************************************************************* 00436 template <typename TIterator> 00437 void assign(TIterator first, TIterator last) 00438 { 00439 #if defined(ETL_DEBUG) 00440 difference_type d = std::distance(first, last); 00441 ETL_ASSERT(d <= difference_type(capacity()), ETL_ERROR(flat_set_full)); 00442 #endif 00443 00444 clear(); 00445 00446 while (first != last) 00447 { 00448 insert(*first++); 00449 } 00450 } 00451 00452 //********************************************************************* 00453 /// Inserts a value to the reference_flat_set. 00454 /// If asserts or exceptions are enabled, emits reference_flat_set_full if the reference_flat_set is already full. 00455 ///\param value The value to insert. 00456 //********************************************************************* 00457 std::pair<iterator, bool> insert(reference value) 00458 { 00459 iterator i_element = lower_bound(value); 00460 00461 return insert_at(i_element, value); 00462 } 00463 00464 //********************************************************************* 00465 /// Inserts a value to the reference_flat_set. 00466 /// If asserts or exceptions are enabled, emits reference_flat_set_full if the reference_flat_set is already full. 00467 ///\param position The position to insert at. 00468 ///\param value The value to insert. 00469 //********************************************************************* 00470 iterator insert(iterator position, reference value) 00471 { 00472 return insert(value).first; 00473 } 00474 00475 //********************************************************************* 00476 /// Inserts a range of values to the reference_flat_set. 00477 /// If asserts or exceptions are enabled, emits reference_flat_set_full if the reference_flat_set does not have enough free space. 00478 ///\param position The position to insert at. 00479 ///\param first The first element to add. 00480 ///\param last The last + 1 element to add. 00481 //********************************************************************* 00482 template <class TIterator> 00483 void insert(TIterator first, TIterator last) 00484 { 00485 while (first != last) 00486 { 00487 insert(*first++); 00488 } 00489 } 00490 00491 //********************************************************************* 00492 /// Erases an element. 00493 ///\param key The key to erase. 00494 ///\return The number of elements erased. 0 or 1. 00495 //********************************************************************* 00496 size_t erase(parameter_t key) 00497 { 00498 iterator i_element = find(key); 00499 00500 if (i_element == end()) 00501 { 00502 return 0; 00503 } 00504 else 00505 { 00506 lookup.erase(i_element.ilookup); 00507 return 1; 00508 } 00509 } 00510 00511 //********************************************************************* 00512 /// Erases an element. 00513 ///\param i_element Iterator to the element. 00514 //********************************************************************* 00515 void erase(iterator i_element) 00516 { 00517 lookup.erase(i_element.ilookup); 00518 } 00519 00520 //********************************************************************* 00521 /// Erases a range of elements. 00522 /// The range includes all the elements between first and last, including the 00523 /// element pointed by first, but not the one pointed by last. 00524 ///\param first Iterator to the first element. 00525 ///\param last Iterator to the last element. 00526 //********************************************************************* 00527 void erase(iterator first, iterator last) 00528 { 00529 lookup.erase(first.ilookup, last.ilookup);; 00530 } 00531 00532 //************************************************************************* 00533 /// Clears the reference_flat_set. 00534 //************************************************************************* 00535 void clear() 00536 { 00537 erase(begin(), end()); 00538 } 00539 00540 //********************************************************************* 00541 /// Finds an element. 00542 ///\param key The key to search for. 00543 ///\return An iterator pointing to the element or end() if not found. 00544 //********************************************************************* 00545 iterator find(parameter_t key) 00546 { 00547 iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); 00548 00549 if (itr != end()) 00550 { 00551 if (!key_compare()(*itr, key) && !key_compare()(key, *itr)) 00552 { 00553 return itr; 00554 } 00555 else 00556 { 00557 return end(); 00558 } 00559 } 00560 00561 return end(); 00562 } 00563 00564 //********************************************************************* 00565 /// Finds an element. 00566 ///\param key The key to search for. 00567 ///\return An iterator pointing to the element or end() if not found. 00568 //********************************************************************* 00569 const_iterator find(parameter_t key) const 00570 { 00571 const_iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); 00572 00573 if (itr != end()) 00574 { 00575 if (!key_compare()(*itr, key) && !key_compare()(key, *itr)) 00576 { 00577 return itr; 00578 } 00579 else 00580 { 00581 return end(); 00582 } 00583 } 00584 00585 return end(); 00586 } 00587 00588 //********************************************************************* 00589 /// Counts an element. 00590 ///\param key The key to search for. 00591 ///\return 1 if the key exists, otherwise 0. 00592 //********************************************************************* 00593 size_t count(parameter_t key) const 00594 { 00595 return (find(key) == end()) ? 0 : 1; 00596 } 00597 00598 //********************************************************************* 00599 /// Finds the lower bound of a key 00600 ///\param key The key to search for. 00601 ///\return An iterator. 00602 //********************************************************************* 00603 iterator lower_bound(parameter_t key) 00604 { 00605 return std::lower_bound(begin(), end(), key, TKeyCompare()); 00606 } 00607 00608 //********************************************************************* 00609 /// Finds the lower bound of a key 00610 ///\param key The key to search for. 00611 ///\return An iterator. 00612 //********************************************************************* 00613 const_iterator lower_bound(parameter_t key) const 00614 { 00615 return std::lower_bound(cbegin(), cend(), key, TKeyCompare()); 00616 } 00617 00618 //********************************************************************* 00619 /// Finds the upper bound of a key 00620 ///\param key The key to search for. 00621 ///\return An iterator. 00622 //********************************************************************* 00623 iterator upper_bound(parameter_t key) 00624 { 00625 return std::upper_bound(begin(), end(), key, TKeyCompare()); 00626 } 00627 00628 //********************************************************************* 00629 /// Finds the upper bound of a key 00630 ///\param key The key to search for. 00631 ///\return An iterator. 00632 //********************************************************************* 00633 const_iterator upper_bound(parameter_t key) const 00634 { 00635 return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); 00636 } 00637 00638 //********************************************************************* 00639 /// Finds the range of equal elements of a key 00640 ///\param key The key to search for. 00641 ///\return An iterator pair. 00642 //********************************************************************* 00643 std::pair<iterator, iterator> equal_range(parameter_t key) 00644 { 00645 return std::equal_range(begin(), end(), key, TKeyCompare()); 00646 } 00647 00648 //********************************************************************* 00649 /// Finds the range of equal elements of a key 00650 ///\param key The key to search for. 00651 ///\return An iterator pair. 00652 //********************************************************************* 00653 std::pair<const_iterator, const_iterator> equal_range(parameter_t key) const 00654 { 00655 return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); 00656 } 00657 00658 //************************************************************************* 00659 /// Gets the current size of the reference_flat_set. 00660 ///\return The current size of the reference_flat_set. 00661 //************************************************************************* 00662 size_type size() const 00663 { 00664 return lookup.size(); 00665 } 00666 00667 //************************************************************************* 00668 /// Checks the 'empty' state of the reference_flat_set. 00669 ///\return <b>true</b> if empty. 00670 //************************************************************************* 00671 bool empty() const 00672 { 00673 return lookup.empty(); 00674 } 00675 00676 //************************************************************************* 00677 /// Checks the 'full' state of the reference_flat_set. 00678 ///\return <b>true</b> if full. 00679 //************************************************************************* 00680 bool full() const 00681 { 00682 return lookup.full(); 00683 } 00684 00685 //************************************************************************* 00686 /// Returns the capacity of the reference_flat_set. 00687 ///\return The capacity of the reference_flat_set. 00688 //************************************************************************* 00689 size_type capacity() const 00690 { 00691 return lookup.capacity(); 00692 } 00693 00694 //************************************************************************* 00695 /// Returns the maximum possible size of the reference_flat_set. 00696 ///\return The maximum size of the reference_flat_set. 00697 //************************************************************************* 00698 size_type max_size() const 00699 { 00700 return lookup.max_size(); 00701 } 00702 00703 //************************************************************************* 00704 /// Returns the remaining capacity. 00705 ///\return The remaining capacity. 00706 //************************************************************************* 00707 size_t available() const 00708 { 00709 return lookup.available(); 00710 } 00711 00712 protected: 00713 00714 //********************************************************************* 00715 /// Constructor. 00716 //********************************************************************* 00717 ireference_flat_set(lookup_t & lookup_) 00718 : lookup(lookup_) 00719 { 00720 } 00721 00722 //********************************************************************* 00723 /// Inserts a value to the reference_flat_set. 00724 ///\param i_element The place to insert. 00725 ///\param value The value to insert. 00726 //********************************************************************* 00727 std::pair<iterator, bool> insert_at(iterator i_element, reference value) 00728 { 00729 std::pair<iterator, bool> result(end(), false); 00730 00731 if (i_element == end()) 00732 { 00733 // At the end. 00734 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_set_full)); 00735 00736 lookup.push_back(&value); 00737 result.first = --end(); 00738 result.second = true; 00739 } 00740 else 00741 { 00742 // Not at the end. 00743 result.first = i_element; 00744 00745 // Existing element? 00746 if (value != *i_element) 00747 { 00748 // A new one. 00749 ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_set_full)); 00750 lookup.insert(i_element.ilookup, &value); 00751 result.second = true; 00752 } 00753 } 00754 00755 return result; 00756 } 00757 00758 private: 00759 00760 // Disable copy construction. 00761 ireference_flat_set(const ireference_flat_set&); 00762 ireference_flat_set& operator =(const ireference_flat_set&); 00763 00764 lookup_t& lookup; 00765 }; 00766 00767 //*************************************************************************** 00768 /// An reference flat set 00769 ///\ingroup reference_flat_set 00770 //*************************************************************************** 00771 template <typename TKey, const size_t MAX_SIZE_, typename TKeyCompare = std::less<TKey> > 00772 class reference_flat_set : public ireference_flat_set<TKey, TKeyCompare> 00773 { 00774 public: 00775 00776 static const size_t MAX_SIZE = MAX_SIZE_; 00777 00778 //************************************************************************* 00779 /// Constructor. 00780 //************************************************************************* 00781 reference_flat_set() 00782 : ireference_flat_set<TKey, TKeyCompare>(lookup) 00783 { 00784 } 00785 00786 //************************************************************************* 00787 /// Copy constructor. 00788 //************************************************************************* 00789 reference_flat_set(const reference_flat_set& other) 00790 : ireference_flat_set<TKey, TKeyCompare>(lookup) 00791 { 00792 ireference_flat_set<TKey, TKeyCompare>::assign(other.cbegin(), other.cend()); 00793 } 00794 00795 //************************************************************************* 00796 /// Constructor, from an iterator range. 00797 ///\tparam TIterator The iterator type. 00798 ///\param first The iterator to the first element. 00799 ///\param last The iterator to the last element + 1. 00800 //************************************************************************* 00801 template <typename TIterator> 00802 reference_flat_set(TIterator first, TIterator last) 00803 : ireference_flat_set<TKey, TKeyCompare>(lookup) 00804 { 00805 ireference_flat_set<TKey, TKeyCompare>::assign(first, last); 00806 } 00807 00808 //************************************************************************* 00809 /// Destructor. 00810 //************************************************************************* 00811 ~reference_flat_set() 00812 { 00813 ireference_flat_set<TKey, TKeyCompare>::clear(); 00814 } 00815 00816 private: 00817 00818 typedef TKey value_type; 00819 00820 // The vector that stores pointers to the nodes. 00821 etl::vector<value_type*, MAX_SIZE> lookup; 00822 }; 00823 00824 //*************************************************************************** 00825 /// Equal operator. 00826 ///\param lhs Reference to the first reference_flat_set. 00827 ///\param rhs Reference to the second reference_flat_set. 00828 ///\return <b>true</b> if the arrays are equal, otherwise <b>false</b> 00829 ///\ingroup reference_flat_set 00830 //*************************************************************************** 00831 template <typename T, typename TKeyCompare> 00832 bool operator ==(const etl::ireference_flat_set<T, TKeyCompare>& lhs, const etl::ireference_flat_set<T, TKeyCompare>& rhs) 00833 { 00834 return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin()); 00835 } 00836 00837 //*************************************************************************** 00838 /// Not equal operator. 00839 ///\param lhs Reference to the first reference_flat_set. 00840 ///\param rhs Reference to the second reference_flat_set. 00841 ///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b> 00842 ///\ingroup reference_flat_set 00843 //*************************************************************************** 00844 template <typename T, typename TKeyCompare> 00845 bool operator !=(const etl::ireference_flat_set<T, TKeyCompare>& lhs, const etl::ireference_flat_set<T, TKeyCompare>& rhs) 00846 { 00847 return !(lhs == rhs); 00848 } 00849 } 00850 00851 #undef ETL_FILE 00852 #endif 00853
Generated on Tue Jul 12 2022 14:05:44 by
