Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers array_view.h Source File

array_view.h

Go to the documentation of this file.
00001 ///\file
00002 
00003 /******************************************************************************
00004 The MIT License(MIT)
00005 
00006 Embedded Template Library.
00007 https://github.com/ETLCPP/etl
00008 https://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_ARRAY_VIEW__
00032 #define __ETL_ARRAY_VIEW__
00033 
00034 #include "platform.h "
00035 #include "memory.h "
00036 #include "iterator.h "
00037 #include "error_handler.h "
00038 #include "exception.h "
00039 #include "nullptr.h "
00040 #include "hash.h "
00041 
00042 #include <algorithm>
00043 
00044 ///\defgroup array array
00045 /// A wrapper for arrays
00046 ///\ingroup containers
00047 
00048 #undef ETL_FILE
00049 #define ETL_FILE "41"
00050 
00051 namespace etl
00052 {
00053   //***************************************************************************
00054   /// The base class for array_view exceptions.
00055   //***************************************************************************
00056   class array_view_exception : public exception
00057   {
00058   public:
00059 
00060     array_view_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 stack
00068   /// The exception thrown when the index is out of bounds.
00069   //***************************************************************************
00070   class array_view_bounds : public array_view_exception
00071   {
00072   public:
00073 
00074     array_view_bounds(string_type file_name_, numeric_type line_number_)
00075       : array_view_exception(ETL_ERROR_TEXT("array_view:bounds", ETL_FILE"A"), file_name_, line_number_)
00076     {
00077     }
00078   };
00079 
00080   //***************************************************************************
00081   ///\ingroup stack
00082   /// The exception thrown when the view is uninitialised.
00083   //***************************************************************************
00084   class array_view_uninitialised : public array_view_exception
00085   {
00086   public:
00087 
00088     array_view_uninitialised(string_type file_name_, numeric_type line_number_)
00089       : array_view_exception(ETL_ERROR_TEXT("array_view:uninitialised", ETL_FILE"B"), file_name_, line_number_)
00090     {
00091     }
00092   };
00093 
00094   //***************************************************************************
00095   /// Array view.
00096   //***************************************************************************
00097   template <typename T>
00098   class array_view
00099   {
00100   public:
00101 
00102     typedef T                                     value_type;
00103     typedef std::size_t                           size_type;
00104     typedef T&                                    reference;
00105     typedef const T&                              const_reference;
00106     typedef T*                                    pointer;
00107     typedef const T*                              const_pointer;
00108     typedef T*                                    iterator;
00109     typedef const T*                              const_iterator;
00110     typedef std::reverse_iterator<iterator>       reverse_iterator;
00111     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00112 
00113     //*************************************************************************
00114     /// Default constructor.
00115     //*************************************************************************
00116     array_view()
00117       : mbegin(std::nullptr),
00118         mend(std::nullptr)
00119     {
00120     }
00121 
00122     //*************************************************************************
00123     /// Construct from std::array or etl::array or other type that supports
00124     /// data() and size() member functions.
00125     //*************************************************************************
00126     template <typename TArray, 
00127               typename TDummy = typename etl::enable_if<!etl::is_same<T, TArray>::value, void>::type>
00128     explicit array_view(TArray& a)
00129       : mbegin(a.data()),
00130         mend(a.data() + a.size())
00131     {
00132     }
00133 
00134     //*************************************************************************
00135     /// Construct from iterators
00136     //*************************************************************************
00137     template <typename TIterator, 
00138               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00139     array_view(TIterator begin_, TIterator end_)
00140       : mbegin(etl::addressof(*begin_)),
00141         mend(etl::addressof(*begin_) + std::distance(begin_, end_))
00142     {
00143     }
00144 
00145     //*************************************************************************
00146     /// Construct from C array
00147     //*************************************************************************
00148     template <typename TIterator, 
00149               typename TSize, 
00150               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00151     array_view(TIterator begin_, TSize size_)
00152       : mbegin(etl::addressof(*begin_)),
00153         mend(etl::addressof(*begin_) + size_)
00154     {
00155     }
00156     
00157     //*************************************************************************
00158     /// Construct from C array
00159     //*************************************************************************
00160     template<const size_t ARRAY_SIZE>
00161     explicit array_view(T(&begin_)[ARRAY_SIZE])
00162       : mbegin(begin_),
00163         mend(begin_ + ARRAY_SIZE)
00164     {
00165     }
00166 
00167     //*************************************************************************
00168     /// Copy constructor
00169     //*************************************************************************
00170     array_view(const array_view& other)
00171       : mbegin(other.mbegin),
00172         mend(other.mend)
00173     {
00174     }
00175 
00176     //*************************************************************************
00177     /// Returns a reference to the first element.
00178     //*************************************************************************
00179     reference front()
00180     {
00181       return *mbegin;
00182     }
00183 
00184     //*************************************************************************
00185     /// Returns a const reference to the first element.
00186     //*************************************************************************
00187     const_reference front() const
00188     {
00189       return *mbegin;
00190     }
00191 
00192     //*************************************************************************
00193     /// Returns a reference to the last element.
00194     //*************************************************************************
00195     reference back()
00196     {
00197       return *(mend - 1);
00198     }
00199 
00200     //*************************************************************************
00201     /// Returns a const reference to the last element.
00202     //*************************************************************************
00203     const_reference back() const
00204     {
00205       return *(mend - 1);
00206     }
00207 
00208     //*************************************************************************
00209     /// Returns a pointer to the first element of the internal storage.
00210     //*************************************************************************
00211     pointer data()
00212     {
00213       return mbegin;
00214     }
00215 
00216     //*************************************************************************
00217     /// Returns a const pointer to the first element of the internal storage.
00218     //*************************************************************************
00219     const_pointer data() const
00220     {
00221       return mbegin;
00222     }
00223 
00224     //*************************************************************************
00225     /// Returns an iterator to the beginning of the array.
00226     //*************************************************************************
00227     iterator begin()
00228     {
00229       return mbegin;
00230     }
00231 
00232     //*************************************************************************
00233     /// Returns a const iterator to the beginning of the array.
00234     //*************************************************************************
00235     const_iterator begin() const
00236     {
00237       return mbegin;
00238     }
00239 
00240     //*************************************************************************
00241     /// Returns a const iterator to the beginning of the array.
00242     //*************************************************************************
00243     const_iterator cbegin() const
00244     {
00245       return mbegin;
00246     }
00247 
00248     //*************************************************************************
00249     /// Returns an iterator to the end of the array.
00250     //*************************************************************************
00251     iterator end()
00252     {
00253       return mend;
00254     }
00255 
00256     //*************************************************************************
00257     /// Returns a const iterator to the end of the array.
00258     //*************************************************************************
00259     const_iterator end() const
00260     {
00261       return mend;
00262     }
00263 
00264     //*************************************************************************
00265     // Returns a const iterator to the end of the array.
00266     //*************************************************************************
00267     const_iterator cend() const
00268     {
00269       return mend;
00270     }
00271 
00272     //*************************************************************************
00273     // Returns an reverse iterator to the reverse beginning of the array.
00274     //*************************************************************************
00275     reverse_iterator rbegin()
00276     {
00277       return reverse_iterator(mend);
00278     }
00279 
00280     //*************************************************************************
00281     /// Returns a const reverse iterator to the reverse beginning of the array.
00282     //*************************************************************************
00283     const_reverse_iterator rbegin() const
00284     {
00285       return const_reverse_iterator(mend);
00286     }
00287 
00288     //*************************************************************************
00289     /// Returns a const reverse iterator to the reverse beginning of the array.
00290     //*************************************************************************
00291     const_reverse_iterator crbegin() const
00292     {
00293       return const_reverse_iterator(mend);
00294     }
00295 
00296     //*************************************************************************
00297     /// Returns a reverse iterator to the end of the array.
00298     //*************************************************************************
00299     reverse_iterator rend()
00300     {
00301       return reverse_iterator(mbegin);
00302     }
00303 
00304     //*************************************************************************
00305     /// Returns a const reverse iterator to the end of the array.
00306     //*************************************************************************
00307     const_reverse_iterator rend() const
00308     {
00309       return const_reverse_iterator(mbegin);
00310     }
00311 
00312     //*************************************************************************
00313     /// Returns a const reverse iterator to the end of the array.
00314     //*************************************************************************
00315     const_reverse_iterator crend() const
00316     {
00317       return const_reverse_iterator(mbegin);
00318     }
00319 
00320     //*************************************************************************
00321     /// Returns <b>true</b> if the array size is zero.
00322     //*************************************************************************
00323     bool empty() const
00324     {
00325       return (mbegin == mend);
00326     }
00327 
00328     //*************************************************************************
00329     /// Returns the size of the array.
00330     //*************************************************************************
00331     size_t size() const
00332     {
00333       return (mend - mbegin);
00334     }
00335 
00336     //*************************************************************************
00337     /// Returns the maximum possible size of the array.
00338     //*************************************************************************
00339     size_t max_size() const
00340     {
00341       return size();
00342     }
00343 
00344     //*************************************************************************
00345     /// Assign from a view.
00346     //*************************************************************************
00347     array_view& operator=(const array_view& other)
00348     {
00349       mbegin = other.mbegin;
00350       mend   = other.mend;
00351       return *this;
00352     }
00353 
00354     //*************************************************************************
00355     /// Assign from iterators
00356     //*************************************************************************
00357     template <typename TIterator,
00358               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00359     void assign(TIterator begin_, TIterator end_)
00360     {
00361       mbegin = etl::addressof(*begin_);
00362       mend = etl::addressof(*begin_) + std::distance(begin_, end_);
00363     }
00364 
00365     //*************************************************************************
00366     /// Assign from iterator and size.
00367     //*************************************************************************
00368     template <typename TIterator,
00369               typename TSize,
00370               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00371     void assign(TIterator begin_, TSize size_)
00372     {
00373       mbegin = etl::addressof(*begin_);
00374       mend = etl::addressof(*begin_) + size_;
00375     }
00376 
00377     //*************************************************************************
00378     /// Returns a reference to the indexed value.
00379     //*************************************************************************
00380     reference operator[](size_t i)
00381     {
00382       return mbegin[i];
00383     }
00384 
00385     //*************************************************************************
00386     /// Returns a const reference to the indexed value.
00387     //*************************************************************************
00388     const_reference operator[](size_t i) const
00389     {
00390       return mbegin[i];
00391     }
00392 
00393     //*************************************************************************
00394     /// Returns a reference to the indexed value.
00395     //*************************************************************************
00396     reference at(size_t i)
00397     {
00398       ETL_ASSERT((mbegin != std::nullptr && mend != std::nullptr), ETL_ERROR(array_view_uninitialised));
00399       ETL_ASSERT(i < size(), ETL_ERROR(array_view_bounds));
00400       return mbegin[i];
00401     }
00402 
00403     //*************************************************************************
00404     /// Returns a const reference to the indexed value.
00405     //*************************************************************************
00406     const_reference at(size_t i) const
00407     {
00408       ETL_ASSERT((mbegin != std::nullptr && mend != std::nullptr), ETL_ERROR(array_view_uninitialised));
00409       ETL_ASSERT(i < size(), ETL_ERROR(array_view_bounds));
00410       return mbegin[i];
00411     }
00412 
00413     //*************************************************************************
00414     /// Swaps with another array_view.
00415     //*************************************************************************
00416     void swap(array_view& other)
00417     {
00418       std::swap(mbegin, other.mbegin);
00419       std::swap(mend, other.mend);
00420     }
00421 
00422     //*************************************************************************          
00423     /// Shrinks the view by moving its start forward.
00424     //*************************************************************************          
00425     void remove_prefix(size_type n)
00426     {
00427       mbegin += n;
00428     }
00429 
00430     //*************************************************************************          
00431     /// Shrinks the view by moving its end backward.
00432     //*************************************************************************          
00433     void remove_suffix(size_type n)
00434     {
00435       mend -= n;
00436     }
00437 
00438     //*************************************************************************
00439     /// Equality for array views.
00440     //*************************************************************************
00441     friend bool operator == (const array_view<T>& lhs, const array_view<T>& rhs)
00442     {
00443       return (lhs.size() == rhs.size()) &&
00444              std::equal(lhs.begin(), lhs.end(), rhs.begin());
00445     }
00446 
00447     //*************************************************************************
00448     /// Inequality for array views.
00449     //*************************************************************************
00450     friend bool operator != (const array_view<T>& lhs, const array_view<T>& rhs)
00451     {
00452       return !(lhs == rhs);
00453     }
00454 
00455     //*************************************************************************
00456     /// Less-than for array views.
00457     //*************************************************************************
00458     friend bool operator < (const array_view<T>& lhs, const array_view<T>& rhs)
00459     {
00460       return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
00461     }
00462 
00463     //*************************************************************************
00464     /// Greater-than for array views.
00465     //*************************************************************************
00466     friend bool operator > (const array_view<T>& lhs, const array_view<T>& rhs)
00467     {
00468       return rhs < lhs;
00469     }
00470 
00471     //*************************************************************************
00472     /// Less-than-equal for array views.
00473     //*************************************************************************
00474     friend bool operator <= (const array_view<T>& lhs, const array_view<T>& rhs)
00475     {
00476       return !(lhs > rhs);
00477     }
00478 
00479     //*************************************************************************
00480     /// Greater-than-equal for array views.
00481     //*************************************************************************
00482     friend bool operator >= (const array_view<T>& lhs, const array_view<T>& rhs)
00483     {
00484       return !(lhs < rhs);
00485     }
00486 
00487   private:
00488 
00489     T* mbegin;
00490     T* mend;
00491   };
00492 
00493   //***************************************************************************
00494   /// Constant array view.
00495   //***************************************************************************
00496   template <typename T>
00497   class const_array_view
00498   {
00499   public:
00500 
00501     typedef T                                     value_type;
00502     typedef std::size_t                           size_type;
00503     typedef const T&                              const_reference;
00504     typedef const T*                              const_pointer;
00505     typedef const T*                              const_iterator;
00506     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00507 
00508     //*************************************************************************
00509     /// Default constructor.
00510     //*************************************************************************
00511     const_array_view()
00512       : mbegin(std::nullptr),
00513         mend(std::nullptr)
00514     {
00515     }
00516 
00517     //*************************************************************************
00518     /// Construct from std::array or etl::array or other type that supports
00519     /// data() and size() member functions.
00520     //*************************************************************************
00521     template <typename TArray, 
00522               typename TDummy = typename etl::enable_if<!etl::is_same<T, TArray>::value, void>::type>
00523     explicit const_array_view(TArray& a)
00524       : mbegin(a.data()),
00525         mend(a.data() + a.size())
00526     {
00527     }
00528 
00529     //*************************************************************************
00530     /// Construct from iterators
00531     //*************************************************************************
00532     template <typename TIterator, 
00533               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00534     const_array_view(TIterator begin_, TIterator end_)
00535       : mbegin(etl::addressof(*begin_)),
00536         mend(etl::addressof(*begin_) + std::distance(begin_, end_))
00537     {
00538     }
00539 
00540     //*************************************************************************
00541     /// Construct from C array
00542     //*************************************************************************
00543     template <typename TIterator, 
00544               typename TSize, typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00545     const_array_view(TIterator begin_, TSize size_)
00546       : mbegin(etl::addressof(*begin_)),
00547         mend(etl::addressof(*begin_) + size_)
00548     {
00549     }
00550 
00551     //*************************************************************************
00552     /// Construct from C array
00553     //*************************************************************************
00554     template<const size_t ARRAY_SIZE>
00555     explicit const_array_view(const T(&begin_)[ARRAY_SIZE])
00556       : mbegin(begin_),
00557         mend(begin_ + ARRAY_SIZE)
00558     {
00559     }
00560 
00561     //*************************************************************************
00562     /// Copy constructor
00563     //*************************************************************************
00564     const_array_view(const array_view<T>& other)
00565       : mbegin(other.begin()),
00566         mend(other.end())
00567     {
00568     }
00569 
00570     //*************************************************************************
00571     /// Copy constructor
00572     //*************************************************************************
00573     const_array_view(const const_array_view& other)
00574       : mbegin(other.mbegin),
00575       mend(other.mend)
00576     {
00577     }
00578 
00579     //*************************************************************************
00580     /// Returns a const reference to the first element.
00581     //*************************************************************************
00582     const_reference front() const
00583     {
00584       return *mbegin;
00585     }
00586 
00587     //*************************************************************************
00588     /// Returns a const reference to the last element.
00589     //*************************************************************************
00590     const_reference back() const
00591     {
00592       return *(mend - 1);
00593     }
00594 
00595     //*************************************************************************
00596     /// Returns a const pointer to the first element of the internal storage.
00597     //*************************************************************************
00598     const_pointer data() const
00599     {
00600       return mbegin;
00601     }
00602 
00603     //*************************************************************************
00604     /// Returns a const iterator to the beginning of the array.
00605     //*************************************************************************
00606     const_iterator begin() const
00607     {
00608       return mbegin;
00609     }
00610 
00611     //*************************************************************************
00612     /// Returns a const iterator to the beginning of the array.
00613     //*************************************************************************
00614     const_iterator cbegin() const
00615     {
00616       return mbegin;
00617     }
00618 
00619     //*************************************************************************
00620     /// Returns a const iterator to the end of the array.
00621     //*************************************************************************
00622     const_iterator end() const
00623     {
00624       return mend;
00625     }
00626 
00627     //*************************************************************************
00628     // Returns a const iterator to the end of the array.
00629     //*************************************************************************
00630     const_iterator cend() const
00631     {
00632       return mend;
00633     }
00634 
00635     //*************************************************************************
00636     /// Returns a const reverse iterator to the reverse beginning of the array.
00637     //*************************************************************************
00638     const_reverse_iterator rbegin() const
00639     {
00640       return const_reverse_iterator(mend);
00641     }
00642 
00643     //*************************************************************************
00644     /// Returns a const reverse iterator to the reverse beginning of the array.
00645     //*************************************************************************
00646     const_reverse_iterator crbegin() const
00647     {
00648       return const_reverse_iterator(mend);
00649     }
00650 
00651     //*************************************************************************
00652     /// Returns a const reverse iterator to the end of the array.
00653     //*************************************************************************
00654     const_reverse_iterator rend() const
00655     {
00656       return const_reverse_iterator(mbegin);
00657     }
00658 
00659     //*************************************************************************
00660     /// Returns a const reverse iterator to the end of the array.
00661     //*************************************************************************
00662     const_reverse_iterator crend() const
00663     {
00664       return const_reverse_iterator(mbegin);
00665     }
00666 
00667     //*************************************************************************
00668     // Capacity
00669     //*************************************************************************
00670 
00671     //*************************************************************************
00672     /// Returns <b>true</b> if the array size is zero.
00673     //*************************************************************************
00674     bool empty() const
00675     {
00676       return (mbegin == mend);
00677     }
00678 
00679     //*************************************************************************
00680     /// Returns the size of the array.
00681     //*************************************************************************
00682     size_t size() const
00683     {
00684       return (mend - mbegin);
00685     }
00686 
00687     //*************************************************************************
00688     /// Returns the maximum possible size of the array.
00689     //*************************************************************************
00690     size_t max_size() const
00691     {
00692       return size();
00693     }
00694 
00695     //*************************************************************************
00696     /// Assign from a view.
00697     //*************************************************************************
00698     const_array_view<T>& operator=(const const_array_view<T>& other)
00699     {
00700       mbegin = other.mbegin;
00701       mend   = other.mend;
00702       return *this;
00703     }
00704 
00705     //*************************************************************************
00706     /// Assign from iterators
00707     //*************************************************************************
00708     template <typename TIterator,
00709       typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00710     void assign(TIterator begin_, TIterator end_)
00711     {
00712       mbegin = etl::addressof(*begin_);
00713       mend   = etl::addressof(*begin_) + std::distance(begin_, end_);
00714     }
00715 
00716     //*************************************************************************
00717     /// Assign from iterator and size.
00718     //*************************************************************************
00719     template <typename TIterator,
00720               typename TSize,
00721               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00722     void assign(TIterator begin_, TSize size_)
00723     {
00724       mbegin = etl::addressof(*begin_);
00725       mend   = etl::addressof(*begin_) + size_;
00726     }
00727 
00728     //*************************************************************************
00729     /// Returns a const reference to the indexed value.
00730     //*************************************************************************
00731     const_reference operator[](size_t i) const
00732     {
00733       return mbegin[i];
00734     }
00735 
00736     //*************************************************************************
00737     /// Returns a const reference to the indexed value.
00738     //*************************************************************************
00739     const_reference at(size_t i) const
00740     {
00741       ETL_ASSERT((mbegin != std::nullptr && mend != std::nullptr), ETL_ERROR(array_view_uninitialised));
00742       ETL_ASSERT(i < size(), ETL_ERROR(array_view_bounds));
00743       return mbegin[i];
00744     }
00745 
00746     //*************************************************************************
00747     /// Swaps with another array_view.
00748     //*************************************************************************
00749     void swap(const_array_view& other)
00750     {
00751       std::swap(mbegin, other.mbegin);
00752       std::swap(mend, other.mend);
00753     }
00754 
00755     //*************************************************************************          
00756     /// Shrinks the view by moving its start forward.
00757     //*************************************************************************          
00758     void remove_prefix(size_type n)
00759     {
00760       mbegin += n;
00761     }
00762 
00763     //*************************************************************************          
00764     /// Shrinks the view by moving its end backward.
00765     //*************************************************************************          
00766     void remove_suffix(size_type n)
00767     {
00768       mend -= n;
00769     }
00770 
00771     //*************************************************************************
00772     /// Equality for array views.
00773     //*************************************************************************
00774     friend bool operator == (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00775     {
00776       return (lhs.size() == rhs.size()) &&
00777         std::equal(lhs.begin(), lhs.end(), rhs.begin());
00778     }
00779 
00780     //*************************************************************************
00781     /// Inequality for array views.
00782     //*************************************************************************
00783     friend bool operator != (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00784     {
00785       return !(lhs == rhs);
00786     }
00787 
00788     //*************************************************************************
00789     /// Less-than for array views.
00790     //*************************************************************************
00791     friend bool operator < (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00792     {
00793       return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
00794     }
00795 
00796     //*************************************************************************
00797     /// Greater-than for array views.
00798     //*************************************************************************
00799     friend bool operator > (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00800     {
00801       return rhs < lhs;
00802     }
00803 
00804     //*************************************************************************
00805     /// Less-than-equal for array views.
00806     //*************************************************************************
00807     friend bool operator <= (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00808     {
00809       return !(lhs > rhs);
00810     }
00811 
00812     //*************************************************************************
00813     /// Greater-than-equal for array views.
00814     //*************************************************************************
00815     friend bool operator >= (const const_array_view<T>& lhs, const const_array_view<T>& rhs)
00816     {
00817       return !(lhs < rhs);
00818     }
00819 
00820   private:
00821 
00822     const T* mbegin;
00823     const T* mend;
00824   };
00825 
00826   //*************************************************************************
00827   /// Hash function.
00828   //*************************************************************************
00829 #if ETL_8BIT_SUPPORT
00830   template <typename T>
00831   struct hash<etl::array_view<T> >
00832   {
00833     size_t operator()(const etl::array_view<T>& view) const
00834     {
00835       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&view[0]),
00836                                                          reinterpret_cast<const uint8_t*>(&view[view.size()]));
00837     }
00838   };
00839  
00840   template <typename T>
00841   struct hash<etl::const_array_view<T> >
00842   {
00843     size_t operator()(const etl::const_array_view<T>& view) const
00844     {
00845       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&view[0]),
00846                                                          reinterpret_cast<const uint8_t*>(&view[view.size()]));
00847     }
00848   };
00849 #endif
00850 }
00851 
00852 //*************************************************************************
00853 /// Swaps the values.
00854 //*************************************************************************
00855 template <typename T>
00856 void swap(etl::array_view<T>& lhs, etl::array_view<T>& rhs)
00857 {
00858   lhs.swap(rhs);
00859 }
00860 
00861 //*************************************************************************
00862 /// Swaps the values.
00863 //*************************************************************************
00864 template <typename T>
00865 void swap(etl::const_array_view<T>& lhs, etl::const_array_view<T>& rhs)
00866 {
00867   lhs.swap(rhs);
00868 }
00869 
00870 #undef ETL_FILE
00871 
00872 #endif
00873 
00874