libstdc++
profile/forward_list
Go to the documentation of this file.
1 // <forward_list> -*- C++ -*-
2 
3 // Copyright (C) 2010-2015 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 #if __cplusplus < 201103L
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  typedef typename _Base::const_iterator const_iterator;
52 
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, const _Alloc& __al = _Alloc())
68  : _Base(__n, __al)
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  typename = std::_RequireInputIter<_InputIterator>>
78  forward_list(_InputIterator __first, _InputIterator __last,
79  const _Alloc& __al = _Alloc())
80  : _Base(__first, __last, __al)
81  { }
82 
83  forward_list(const forward_list&) = default;
84  forward_list(forward_list&&) = default;
85 
86  forward_list(std::initializer_list<_Tp> __il,
87  const _Alloc& __al = _Alloc())
88  : _Base(__il, __al)
89  { }
90 
91  ~forward_list() = default;
92 
93  forward_list&
94  operator=(const forward_list&) = default;
95 
96  forward_list&
97  operator=(forward_list&&) = default;
98 
99  forward_list&
100  operator=(std::initializer_list<_Tp> __il)
101  {
102  _M_base() = __il;
103  return *this;
104  }
105 
106  void
107  swap(forward_list& __fl)
108  noexcept( noexcept(declval<_Base>().swap(__fl)) )
109  { _Base::swap(__fl); }
110 
111  void
112  splice_after(const_iterator __pos, forward_list&& __fl)
113  { _Base::splice_after(__pos, std::move(__fl)); }
114 
115  void
116  splice_after(const_iterator __pos, forward_list& __list)
117  { _Base::splice_after(__pos, __list); }
118 
119  void
120  splice_after(const_iterator __pos, forward_list&& __list,
121  const_iterator __i)
122  { _Base::splice_after(__pos, std::move(__list), __i); }
123 
124  void
125  splice_after(const_iterator __pos, forward_list& __list,
126  const_iterator __i)
127  { _Base::splice_after(__pos, __list, __i); }
128 
129  void
130  splice_after(const_iterator __pos, forward_list&& __list,
131  const_iterator __before, const_iterator __last)
132  { _Base::splice_after(__pos, std::move(__list), __before, __last); }
133 
134  void
135  splice_after(const_iterator __pos, forward_list& __list,
136  const_iterator __before, const_iterator __last)
137  { _Base::splice_after(__pos, __list, __before, __last); }
138 
139  void
140  merge(forward_list&& __list)
141  { _Base::merge(std::move(__list)); }
142 
143  void
144  merge(forward_list& __list)
145  { _Base::merge(__list); }
146 
147  template<typename _Comp>
148  void
149  merge(forward_list&& __list, _Comp __comp)
150  { _Base::merge(std::move(__list), __comp); }
151 
152  template<typename _Comp>
153  void
154  merge(forward_list& __list, _Comp __comp)
155  { _Base::merge(__list, __comp); }
156 
157  _Base&
158  _M_base() noexcept { return *this; }
159 
160  const _Base&
161  _M_base() const noexcept { return *this; }
162  };
163 
164  template<typename _Tp, typename _Alloc>
165  inline bool
166  operator==(const forward_list<_Tp, _Alloc>& __lx,
167  const forward_list<_Tp, _Alloc>& __ly)
168  { return __lx._M_base() == __ly._M_base(); }
169 
170  template<typename _Tp, typename _Alloc>
171  inline bool
172  operator<(const forward_list<_Tp, _Alloc>& __lx,
173  const forward_list<_Tp, _Alloc>& __ly)
174  { return __lx._M_base() < __ly._M_base(); }
175 
176  template<typename _Tp, typename _Alloc>
177  inline bool
178  operator!=(const forward_list<_Tp, _Alloc>& __lx,
179  const forward_list<_Tp, _Alloc>& __ly)
180  { return !(__lx == __ly); }
181 
182  /// Based on operator<
183  template<typename _Tp, typename _Alloc>
184  inline bool
185  operator>(const forward_list<_Tp, _Alloc>& __lx,
186  const forward_list<_Tp, _Alloc>& __ly)
187  { return (__ly < __lx); }
188 
189  /// Based on operator<
190  template<typename _Tp, typename _Alloc>
191  inline bool
192  operator>=(const forward_list<_Tp, _Alloc>& __lx,
193  const forward_list<_Tp, _Alloc>& __ly)
194  { return !(__lx < __ly); }
195 
196  /// Based on operator<
197  template<typename _Tp, typename _Alloc>
198  inline bool
199  operator<=(const forward_list<_Tp, _Alloc>& __lx,
200  const forward_list<_Tp, _Alloc>& __ly)
201  { return !(__ly < __lx); }
202 
203  /// See std::forward_list::swap().
204  template<typename _Tp, typename _Alloc>
205  inline void
206  swap(forward_list<_Tp, _Alloc>& __lx,
207  forward_list<_Tp, _Alloc>& __ly)
208  { __lx.swap(__ly); }
209 
210 } // namespace __profile
211 } // namespace std
212 
213 #endif // C++11
214 
215 #endif