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