1 // <forward_list> -*- C++ -*- 2 3 // Copyright (C) 2010 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 // <http://www.gnu.org/licenses/>. 24 25 /** @file profile/forward_list 26 * This file is a GNU debug extension to the Standard C++ Library. 27 */ 28 29 #ifndef _GLIBCXX_PROFILE_FORWARD_LIST 30 #define _GLIBCXX_PROFILE_FORWARD_LIST 1 31 32 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 33 # include <bits/c++0x_warning.h> 34 #else 35 36 #include <forward_list> 37 38 namespace std _GLIBCXX_VISIBILITY(default) 39 { 40 namespace __profile 41 { 42 /// Class std::forward_list wrapper with performance instrumentation. 43 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 44 class forward_list 45 : public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> 46 { 47 typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base; 48 49 public: 50 typedef typename _Base::size_type size_type; 51 52 public: 53 // 23.2.3.1 construct/copy/destroy: 54 explicit 55 forward_list(const _Alloc& __al = _Alloc()) 56 : _Base(__al) { } 57 58 forward_list(const forward_list& __list, const _Alloc& __al) 59 : _Base(__list, __al) 60 { } 61 62 forward_list(forward_list&& __list, const _Alloc& __al) 63 : _Base(std::move(__list), __al) 64 { } 65 66 explicit 67 forward_list(size_type __n) 68 : _Base(__n) 69 { } 70 71 forward_list(size_type __n, const _Tp& __value, 72 const _Alloc& __al = _Alloc()) 73 : _Base(__n, __value, __al) 74 { } 75 76 template<typename _InputIterator> 77 forward_list(_InputIterator __first, _InputIterator __last, 78 const _Alloc& __al = _Alloc()) 79 : _Base(__first, __last, __al) 80 { } 81 82 forward_list(const forward_list& __list) 83 : _Base(__list) 84 { } 85 86 forward_list(forward_list&& __list) 87 : _Base(std::move(__list)) { } 88 89 forward_list(std::initializer_list<_Tp> __il, 90 const _Alloc& __al = _Alloc()) 91 : _Base(__il, __al) 92 { } 93 94 ~forward_list() 95 { } 96 97 forward_list& 98 operator=(const forward_list& __list) 99 { 100 static_cast<_Base&>(*this) = __list; 101 return *this; 102 } 103 104 forward_list& 105 operator=(forward_list&& __list) 106 { 107 // NB: DR 1204. 108 // NB: DR 675. 109 _Base::clear(); 110 _Base::swap(__list); 111 return *this; 112 } 113 114 forward_list& 115 operator=(std::initializer_list<_Tp> __il) 116 { 117 static_cast<_Base&>(*this) = __il; 118 return *this; 119 } 120 121 _Base& 122 _M_base() { return *this; } 123 124 const _Base& 125 _M_base() const { return *this; } 126 }; 127 128 template<typename _Tp, typename _Alloc> 129 inline bool 130 operator==(const forward_list<_Tp, _Alloc>& __lx, 131 const forward_list<_Tp, _Alloc>& __ly) 132 { return __lx._M_base() == __ly._M_base(); } 133 134 template<typename _Tp, typename _Alloc> 135 inline bool 136 operator<(const forward_list<_Tp, _Alloc>& __lx, 137 const forward_list<_Tp, _Alloc>& __ly) 138 { return __lx._M_base() < __ly._M_base(); } 139 140 template<typename _Tp, typename _Alloc> 141 inline bool 142 operator!=(const forward_list<_Tp, _Alloc>& __lx, 143 const forward_list<_Tp, _Alloc>& __ly) 144 { return !(__lx == __ly); } 145 146 /// Based on operator< 147 template<typename _Tp, typename _Alloc> 148 inline bool 149 operator>(const forward_list<_Tp, _Alloc>& __lx, 150 const forward_list<_Tp, _Alloc>& __ly) 151 { return (__ly < __lx); } 152 153 /// Based on operator< 154 template<typename _Tp, typename _Alloc> 155 inline bool 156 operator>=(const forward_list<_Tp, _Alloc>& __lx, 157 const forward_list<_Tp, _Alloc>& __ly) 158 { return !(__lx < __ly); } 159 160 /// Based on operator< 161 template<typename _Tp, typename _Alloc> 162 inline bool 163 operator<=(const forward_list<_Tp, _Alloc>& __lx, 164 const forward_list<_Tp, _Alloc>& __ly) 165 { return !(__ly < __lx); } 166 167 /// See std::forward_list::swap(). 168 template<typename _Tp, typename _Alloc> 169 inline void 170 swap(forward_list<_Tp, _Alloc>& __lx, 171 forward_list<_Tp, _Alloc>& __ly) 172 { __lx.swap(__ly); } 173 174 } // namespace __profile 175 } // namespace std 176 177 #endif // __GXX_EXPERIMENTAL_CXX0X__ 178 179 #endif 180