libstdc++
range_access.h
Go to the documentation of this file.
00001 // <range_access.h> -*- C++ -*-
00002 
00003 // Copyright (C) 2010-2015 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/range_access.h
00026  *  This is an internal header file, included by other library headers.
00027  *  Do not attempt to use it directly. @headername{iterator}
00028  */
00029 
00030 #ifndef _GLIBCXX_RANGE_ACCESS_H
00031 #define _GLIBCXX_RANGE_ACCESS_H 1
00032 
00033 #pragma GCC system_header
00034 
00035 #if __cplusplus >= 201103L
00036 #include <initializer_list>
00037 namespace std _GLIBCXX_VISIBILITY(default)
00038 {
00039 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00040 
00041   /**
00042    *  @brief  Return an iterator pointing to the first element of
00043    *          the container.
00044    *  @param  __cont  Container.
00045    */
00046   template<class _Container>
00047     inline auto
00048     begin(_Container& __cont) -> decltype(__cont.begin())
00049     { return __cont.begin(); }
00050 
00051   /**
00052    *  @brief  Return an iterator pointing to the first element of
00053    *          the const container.
00054    *  @param  __cont  Container.
00055    */
00056   template<class _Container>
00057     inline auto
00058     begin(const _Container& __cont) -> decltype(__cont.begin())
00059     { return __cont.begin(); }
00060 
00061   /**
00062    *  @brief  Return an iterator pointing to one past the last element of
00063    *          the container.
00064    *  @param  __cont  Container.
00065    */
00066   template<class _Container>
00067     inline auto
00068     end(_Container& __cont) -> decltype(__cont.end())
00069     { return __cont.end(); }
00070 
00071   /**
00072    *  @brief  Return an iterator pointing to one past the last element of
00073    *          the const container.
00074    *  @param  __cont  Container.
00075    */
00076   template<class _Container>
00077     inline auto
00078     end(const _Container& __cont) -> decltype(__cont.end())
00079     { return __cont.end(); }
00080 
00081   /**
00082    *  @brief  Return an iterator pointing to the first element of the array.
00083    *  @param  __arr  Array.
00084    */
00085   template<class _Tp, size_t _Nm>
00086     inline _GLIBCXX14_CONSTEXPR _Tp*
00087     begin(_Tp (&__arr)[_Nm])
00088     { return __arr; }
00089 
00090   /**
00091    *  @brief  Return an iterator pointing to one past the last element
00092    *          of the array.
00093    *  @param  __arr  Array.
00094    */
00095   template<class _Tp, size_t _Nm>
00096     inline _GLIBCXX14_CONSTEXPR _Tp*
00097     end(_Tp (&__arr)[_Nm])
00098     { return __arr + _Nm; }
00099 
00100 #if __cplusplus >= 201402L
00101   /**
00102    *  @brief  Return an iterator pointing to the first element of
00103    *          the const container.
00104    *  @param  __cont  Container.
00105    */
00106   template<class _Container>
00107     inline constexpr auto
00108     cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont)))
00109       -> decltype(std::begin(__cont))
00110     { return std::begin(__cont); }
00111 
00112   /**
00113    *  @brief  Return an iterator pointing to one past the last element of
00114    *          the const container.
00115    *  @param  __cont  Container.
00116    */
00117   template<class _Container>
00118     inline constexpr auto
00119     cend(const _Container& __cont) noexcept(noexcept(std::end(__cont)))
00120       -> decltype(std::end(__cont))
00121     { return std::end(__cont); }
00122 
00123   /**
00124    *  @brief  Return a reverse iterator pointing to the last element of
00125    *          the container.
00126    *  @param  __cont  Container.
00127    */
00128   template<class _Container>
00129     inline auto
00130     rbegin(_Container& __cont) -> decltype(__cont.rbegin())
00131     { return __cont.rbegin(); }
00132 
00133   /**
00134    *  @brief  Return a reverse iterator pointing to the last element of
00135    *          the const container.
00136    *  @param  __cont  Container.
00137    */
00138   template<class _Container>
00139     inline auto
00140     rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
00141     { return __cont.rbegin(); }
00142 
00143   /**
00144    *  @brief  Return a reverse iterator pointing one past the first element of
00145    *          the container.
00146    *  @param  __cont  Container.
00147    */
00148   template<class _Container>
00149     inline auto
00150     rend(_Container& __cont) -> decltype(__cont.rend())
00151     { return __cont.rend(); }
00152 
00153   /**
00154    *  @brief  Return a reverse iterator pointing one past the first element of
00155    *          the const container.
00156    *  @param  __cont  Container.
00157    */
00158   template<class _Container>
00159     inline auto
00160     rend(const _Container& __cont) -> decltype(__cont.rend())
00161     { return __cont.rend(); }
00162 
00163   /**
00164    *  @brief  Return a reverse iterator pointing to the last element of
00165    *          the array.
00166    *  @param  __arr  Array.
00167    */
00168   template<class _Tp, size_t _Nm>
00169     inline reverse_iterator<_Tp*>
00170     rbegin(_Tp (&__arr)[_Nm])
00171     { return reverse_iterator<_Tp*>(__arr + _Nm); }
00172 
00173   /**
00174    *  @brief  Return a reverse iterator pointing one past the first element of
00175    *          the array.
00176    *  @param  __arr  Array.
00177    */
00178   template<class _Tp, size_t _Nm>
00179     inline reverse_iterator<_Tp*>
00180     rend(_Tp (&__arr)[_Nm])
00181     { return reverse_iterator<_Tp*>(__arr); }
00182 
00183   /**
00184    *  @brief  Return a reverse iterator pointing to the last element of
00185    *          the initializer_list.
00186    *  @param  __il  initializer_list.
00187    */
00188   template<class _Tp>
00189     inline reverse_iterator<const _Tp*>
00190     rbegin(initializer_list<_Tp> __il)
00191     { return reverse_iterator<const _Tp*>(__il.end()); }
00192 
00193   /**
00194    *  @brief  Return a reverse iterator pointing one past the first element of
00195    *          the initializer_list.
00196    *  @param  __il  initializer_list.
00197    */
00198   template<class _Tp>
00199     inline reverse_iterator<const _Tp*>
00200     rend(initializer_list<_Tp> __il)
00201     { return reverse_iterator<const _Tp*>(__il.begin()); }
00202 
00203   /**
00204    *  @brief  Return a reverse iterator pointing to the last element of
00205    *          the const container.
00206    *  @param  __cont  Container.
00207    */
00208   template<class _Container>
00209     inline auto
00210     crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
00211     { return std::rbegin(__cont); }
00212 
00213   /**
00214    *  @brief  Return a reverse iterator pointing one past the first element of
00215    *          the const container.
00216    *  @param  __cont  Container.
00217    */
00218   template<class _Container>
00219     inline auto
00220     crend(const _Container& __cont) -> decltype(std::rend(__cont))
00221     { return std::rend(__cont); }
00222 
00223 #endif // C++14
00224 
00225 _GLIBCXX_END_NAMESPACE_VERSION
00226 } // namespace
00227 
00228 #endif // C++11
00229 
00230 #endif // _GLIBCXX_RANGE_ACCESS_H