libstdc++
profile/forward_list
Go to the documentation of this file.
00001 // <forward_list> -*- C++ -*-
00002 
00003 // Copyright (C) 2010, 2011 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 #ifndef __GXX_EXPERIMENTAL_CXX0X__
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     public:
00050       typedef typename _Base::size_type             size_type;
00051 
00052     public:
00053       // 23.2.3.1 construct/copy/destroy:
00054       explicit
00055       forward_list(const _Alloc& __al = _Alloc())
00056       : _Base(__al) { }
00057 
00058       forward_list(const forward_list& __list, const _Alloc& __al)
00059       : _Base(__list, __al)
00060       { }
00061 
00062       forward_list(forward_list&& __list, const _Alloc& __al)
00063       : _Base(std::move(__list), __al)
00064       { }
00065 
00066       explicit
00067       forward_list(size_type __n)
00068       : _Base(__n)
00069       { }
00070 
00071       forward_list(size_type __n, const _Tp& __value,
00072                    const _Alloc& __al = _Alloc())
00073       : _Base(__n, __value, __al)
00074       { }
00075 
00076       template<typename _InputIterator>
00077         forward_list(_InputIterator __first, _InputIterator __last,
00078                      const _Alloc& __al = _Alloc())
00079         : _Base(__first, __last, __al)
00080         { }
00081 
00082       forward_list(const forward_list& __list)
00083       : _Base(__list)
00084       { }
00085 
00086       forward_list(forward_list&& __list) noexcept
00087       : _Base(std::move(__list)) { }
00088 
00089       forward_list(std::initializer_list<_Tp> __il,
00090                    const _Alloc& __al = _Alloc())
00091       : _Base(__il, __al)
00092       { }
00093 
00094       ~forward_list() noexcept
00095       { }
00096 
00097       forward_list&
00098       operator=(const forward_list& __list)
00099       {
00100     static_cast<_Base&>(*this) = __list;
00101     return *this;
00102       }
00103 
00104       forward_list&
00105       operator=(forward_list&& __list)
00106       {
00107     // NB: DR 1204.
00108     // NB: DR 675.
00109     _Base::clear();
00110     _Base::swap(__list);
00111     return *this;
00112       }
00113 
00114       forward_list&
00115       operator=(std::initializer_list<_Tp> __il)
00116       {
00117     static_cast<_Base&>(*this) = __il;
00118         return *this;
00119       }
00120 
00121       _Base&
00122       _M_base() noexcept       { return *this; }
00123 
00124       const _Base&
00125       _M_base() const noexcept { return *this; }
00126     };
00127 
00128   template<typename _Tp, typename _Alloc>
00129     inline bool
00130     operator==(const forward_list<_Tp, _Alloc>& __lx,
00131                const forward_list<_Tp, _Alloc>& __ly)
00132     { return __lx._M_base() == __ly._M_base(); }
00133 
00134   template<typename _Tp, typename _Alloc>
00135     inline bool
00136     operator<(const forward_list<_Tp, _Alloc>& __lx,
00137               const forward_list<_Tp, _Alloc>& __ly)
00138     { return __lx._M_base() < __ly._M_base(); }
00139 
00140   template<typename _Tp, typename _Alloc>
00141     inline bool
00142     operator!=(const forward_list<_Tp, _Alloc>& __lx,
00143                const forward_list<_Tp, _Alloc>& __ly)
00144     { return !(__lx == __ly); }
00145 
00146   /// Based on operator<
00147   template<typename _Tp, typename _Alloc>
00148     inline bool
00149     operator>(const forward_list<_Tp, _Alloc>& __lx,
00150               const forward_list<_Tp, _Alloc>& __ly)
00151     { return (__ly < __lx); }
00152 
00153   /// Based on operator<
00154   template<typename _Tp, typename _Alloc>
00155     inline bool
00156     operator>=(const forward_list<_Tp, _Alloc>& __lx,
00157                const forward_list<_Tp, _Alloc>& __ly)
00158     { return !(__lx < __ly); }
00159 
00160   /// Based on operator<
00161   template<typename _Tp, typename _Alloc>
00162     inline bool
00163     operator<=(const forward_list<_Tp, _Alloc>& __lx,
00164                const forward_list<_Tp, _Alloc>& __ly)
00165     { return !(__ly < __lx); }
00166 
00167   /// See std::forward_list::swap().
00168   template<typename _Tp, typename _Alloc>
00169     inline void
00170     swap(forward_list<_Tp, _Alloc>& __lx,
00171      forward_list<_Tp, _Alloc>& __ly)
00172     { __lx.swap(__ly); }
00173 
00174 } // namespace __profile
00175 } // namespace std
00176 
00177 #endif // __GXX_EXPERIMENTAL_CXX0X__
00178 
00179 #endif