libstdc++
forward_list
Go to the documentation of this file.
00001 // <forward_list> -*- C++ -*-
00002 
00003 // Copyright (C) 2010-2013 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 profile/forward_list
00026  *  This file is a GNU debug extension to the Standard C++ Library.
00027  */
00028 
00029 #ifndef _GLIBCXX_PROFILE_FORWARD_LIST
00030 #define _GLIBCXX_PROFILE_FORWARD_LIST 1
00031 
00032 #if __cplusplus < 201103L
00033 # include <bits/c++0x_warning.h>
00034 #else
00035 
00036 #include <forward_list>
00037 
00038 namespace std _GLIBCXX_VISIBILITY(default)
00039 {
00040 namespace __profile
00041 {
00042   /// Class std::forward_list wrapper with performance instrumentation.
00043   template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00044     class forward_list
00045     : public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
00046     {
00047       typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base;
00048 
00049       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
00050         rebind<_GLIBCXX_STD_C::_Fwd_list_node<_Tp>>::other _Node_alloc_type;
00051 
00052       typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
00053 
00054     public:
00055       typedef typename _Base::size_type             size_type;
00056 
00057       // 23.2.3.1 construct/copy/destroy:
00058       explicit
00059       forward_list(const _Alloc& __al = _Alloc())
00060       : _Base(__al) { }
00061 
00062       forward_list(const forward_list& __list, const _Alloc& __al)
00063       : _Base(__list, __al)
00064       { }
00065 
00066       forward_list(forward_list&& __list, const _Alloc& __al)
00067       : _Base(std::move(__list), __al)
00068       { }
00069 
00070       explicit
00071       forward_list(size_type __n, const _Alloc& __al = _Alloc())
00072       : _Base(__n, __al)
00073       { }
00074 
00075       forward_list(size_type __n, const _Tp& __value,
00076                    const _Alloc& __al = _Alloc())
00077       : _Base(__n, __value, __al)
00078       { }
00079 
00080       template<typename _InputIterator,
00081            typename = std::_RequireInputIter<_InputIterator>>
00082         forward_list(_InputIterator __first, _InputIterator __last,
00083                      const _Alloc& __al = _Alloc())
00084         : _Base(__first, __last, __al)
00085         { }
00086 
00087       forward_list(const forward_list& __list)
00088       : _Base(__list)
00089       { }
00090 
00091       forward_list(forward_list&& __list) noexcept
00092       : _Base(std::move(__list)) { }
00093 
00094       forward_list(std::initializer_list<_Tp> __il,
00095                    const _Alloc& __al = _Alloc())
00096       : _Base(__il, __al)
00097       { }
00098 
00099       ~forward_list() noexcept
00100       { }
00101 
00102       forward_list&
00103       operator=(const forward_list& __list)
00104       {
00105     static_cast<_Base&>(*this) = __list;
00106     return *this;
00107       }
00108 
00109       forward_list&
00110       operator=(forward_list&& __list)
00111       noexcept(_Node_alloc_traits::_S_nothrow_move())
00112       {
00113     static_cast<_Base&>(*this) = std::move(__list);
00114     return *this;
00115       }
00116 
00117       forward_list&
00118       operator=(std::initializer_list<_Tp> __il)
00119       {
00120     static_cast<_Base&>(*this) = __il;
00121         return *this;
00122       }
00123 
00124       _Base&
00125       _M_base() noexcept       { return *this; }
00126 
00127       const _Base&
00128       _M_base() const noexcept { return *this; }
00129     };
00130 
00131   template<typename _Tp, typename _Alloc>
00132     inline bool
00133     operator==(const forward_list<_Tp, _Alloc>& __lx,
00134                const forward_list<_Tp, _Alloc>& __ly)
00135     { return __lx._M_base() == __ly._M_base(); }
00136 
00137   template<typename _Tp, typename _Alloc>
00138     inline bool
00139     operator<(const forward_list<_Tp, _Alloc>& __lx,
00140               const forward_list<_Tp, _Alloc>& __ly)
00141     { return __lx._M_base() < __ly._M_base(); }
00142 
00143   template<typename _Tp, typename _Alloc>
00144     inline bool
00145     operator!=(const forward_list<_Tp, _Alloc>& __lx,
00146                const forward_list<_Tp, _Alloc>& __ly)
00147     { return !(__lx == __ly); }
00148 
00149   /// Based on operator<
00150   template<typename _Tp, typename _Alloc>
00151     inline bool
00152     operator>(const forward_list<_Tp, _Alloc>& __lx,
00153               const forward_list<_Tp, _Alloc>& __ly)
00154     { return (__ly < __lx); }
00155 
00156   /// Based on operator<
00157   template<typename _Tp, typename _Alloc>
00158     inline bool
00159     operator>=(const forward_list<_Tp, _Alloc>& __lx,
00160                const forward_list<_Tp, _Alloc>& __ly)
00161     { return !(__lx < __ly); }
00162 
00163   /// Based on operator<
00164   template<typename _Tp, typename _Alloc>
00165     inline bool
00166     operator<=(const forward_list<_Tp, _Alloc>& __lx,
00167                const forward_list<_Tp, _Alloc>& __ly)
00168     { return !(__ly < __lx); }
00169 
00170   /// See std::forward_list::swap().
00171   template<typename _Tp, typename _Alloc>
00172     inline void
00173     swap(forward_list<_Tp, _Alloc>& __lx,
00174      forward_list<_Tp, _Alloc>& __ly)
00175     { __lx.swap(__ly); }
00176 
00177 } // namespace __profile
00178 } // namespace std
00179 
00180 #endif // C++11
00181 
00182 #endif