libstdc++
profile/forward_list
Go to the documentation of this file.
1 // <forward_list> -*- C++ -*-
2 
3 // Copyright (C) 2010-2014 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> >
45  : public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
46  {
47  typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base;
48 
50  rebind<_GLIBCXX_STD_C::_Fwd_list_node<_Tp>>::other _Node_alloc_type;
51 
53 
54  public:
55  typedef typename _Base::size_type size_type;
56 
57  // 23.2.3.1 construct/copy/destroy:
58  explicit
59  forward_list(const _Alloc& __al = _Alloc())
60  : _Base(__al) { }
61 
62  forward_list(const forward_list& __list, const _Alloc& __al)
63  : _Base(__list, __al)
64  { }
65 
66  forward_list(forward_list&& __list, const _Alloc& __al)
67  : _Base(std::move(__list), __al)
68  { }
69 
70  explicit
71  forward_list(size_type __n, const _Alloc& __al = _Alloc())
72  : _Base(__n, __al)
73  { }
74 
75  forward_list(size_type __n, const _Tp& __value,
76  const _Alloc& __al = _Alloc())
77  : _Base(__n, __value, __al)
78  { }
79 
80  template<typename _InputIterator,
81  typename = std::_RequireInputIter<_InputIterator>>
82  forward_list(_InputIterator __first, _InputIterator __last,
83  const _Alloc& __al = _Alloc())
84  : _Base(__first, __last, __al)
85  { }
86 
87  forward_list(const forward_list& __list)
88  : _Base(__list)
89  { }
90 
91  forward_list(forward_list&& __list) noexcept
92  : _Base(std::move(__list)) { }
93 
94  forward_list(std::initializer_list<_Tp> __il,
95  const _Alloc& __al = _Alloc())
96  : _Base(__il, __al)
97  { }
98 
99  ~forward_list() noexcept
100  { }
101 
102  forward_list&
103  operator=(const forward_list& __list)
104  {
105  static_cast<_Base&>(*this) = __list;
106  return *this;
107  }
108 
109  forward_list&
110  operator=(forward_list&& __list)
111  noexcept(_Node_alloc_traits::_S_nothrow_move())
112  {
113  static_cast<_Base&>(*this) = std::move(__list);
114  return *this;
115  }
116 
117  forward_list&
118  operator=(std::initializer_list<_Tp> __il)
119  {
120  static_cast<_Base&>(*this) = __il;
121  return *this;
122  }
123 
124  _Base&
125  _M_base() noexcept { return *this; }
126 
127  const _Base&
128  _M_base() const noexcept { return *this; }
129  };
130 
131  template<typename _Tp, typename _Alloc>
132  inline bool
133  operator==(const forward_list<_Tp, _Alloc>& __lx,
134  const forward_list<_Tp, _Alloc>& __ly)
135  { return __lx._M_base() == __ly._M_base(); }
136 
137  template<typename _Tp, typename _Alloc>
138  inline bool
139  operator<(const forward_list<_Tp, _Alloc>& __lx,
140  const forward_list<_Tp, _Alloc>& __ly)
141  { return __lx._M_base() < __ly._M_base(); }
142 
143  template<typename _Tp, typename _Alloc>
144  inline bool
145  operator!=(const forward_list<_Tp, _Alloc>& __lx,
146  const forward_list<_Tp, _Alloc>& __ly)
147  { return !(__lx == __ly); }
148 
149  /// Based on operator<
150  template<typename _Tp, typename _Alloc>
151  inline bool
152  operator>(const forward_list<_Tp, _Alloc>& __lx,
153  const forward_list<_Tp, _Alloc>& __ly)
154  { return (__ly < __lx); }
155 
156  /// Based on operator<
157  template<typename _Tp, typename _Alloc>
158  inline bool
159  operator>=(const forward_list<_Tp, _Alloc>& __lx,
160  const forward_list<_Tp, _Alloc>& __ly)
161  { return !(__lx < __ly); }
162 
163  /// Based on operator<
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 !(__ly < __lx); }
169 
170  /// See std::forward_list::swap().
171  template<typename _Tp, typename _Alloc>
172  inline void
175  { __lx.swap(__ly); }
176 
177 } // namespace __profile
178 } // namespace std
179 
180 #endif // C++11
181 
182 #endif
Uniform interface to C++98 and C++0x allocators.
Class std::forward_list wrapper with performance instrumentation.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
Definition: functional:2534
initializer_list
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
Definition: forward_list.h:414