mCRL2
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote, Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9//
17
18#ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_VECTOR_H
19#define MCRL2_ATERMPP_STANDARD_CONTAINER_VECTOR_H
20
21#include <vector>
22
26
28namespace atermpp
29{
30
32template < class T, class Alloc = std::allocator<detail::reference_aterm<T> >, bool ThreadSafe = false >
33class vector : public std::vector< detail::reference_aterm<T>, Alloc >
34{
35protected:
36 typedef std::vector< detail::reference_aterm<T>, Alloc > super;
37
39
40public:
42 typedef typename super::allocator_type allocator_type;
43 typedef typename super::value_type value_type;
44 typedef typename super::size_type size_type;
45 typedef typename super::reference reference;
46 typedef typename super::iterator iterator;
47 typedef typename super::const_iterator const_iterator;
48
51 : super(),
53 {}
54
56 explicit vector (const allocator_type& alloc)
57 : super::vector(alloc),
58 container_wrapper(*this)
59 {}
60
62 explicit vector (size_type n, const allocator_type& alloc = allocator_type())
63 : super::vector(n, alloc),
64 container_wrapper(*this)
65 {}
66
67 vector (size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
68 : super::vector(n, detail::reference_aterm(val), alloc),
70 {}
71
73 template <class InputIterator>
74 vector (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
75 : super::vector(first, last, alloc),
76 container_wrapper(*this)
77 {}
78
80 vector (const vector& x)
81 : super::vector(x),
82 container_wrapper(*this)
83 {}
84
86 vector (const vector& x, const allocator_type& alloc)
87 : super::vector(x, alloc),
88 container_wrapper(*this)
89 {}
90
93 : super::vector(std::move(x)),
94 container_wrapper(*this)
95 {}
96
98 vector (vector&& x, const allocator_type& alloc)
99 : super::vector(std::move(x), alloc),
100 container_wrapper(*this)
101 {}
102
104 vector (std::initializer_list<value_type> il, const allocator_type& alloc = allocator_type())
105 : super::vector(il, alloc),
106 container_wrapper(*this)
107 {}
108
110 vector& operator=(const vector& x) = default;
111
113 vector& operator=(vector&& x) = default;
114
117
119 {
120 if constexpr (ThreadSafe) {
122 super::shrink_to_fit();
123 } else {
125 super::shrink_to_fit();
126 }
127 }
128
129 void clear() noexcept
130 {
131 if constexpr (ThreadSafe) {
133 super::clear();
134 } else {
136 super::clear();
137 }
138 }
139
140 iterator insert( const_iterator pos, const T& value )
141 {
142 if constexpr (ThreadSafe) {
144
145 // This is not thread safe otherwise since the length or end iterator is updated during this producedure.
146 return super::insert(pos, value);
147 }
148
150 return super::insert(pos, value);
151 }
152
154 {
155 if constexpr (ThreadSafe) {
157 return super::insert(pos, value);
158 }
159
161 return super::insert(pos, value);
162 }
163
164 iterator insert( const_iterator pos, size_type count, const T& value )
165 {
166 if constexpr (ThreadSafe) {
168 return super::insert(pos, count, value);
169 }
170
172 return super::insert(pos, count, value);
173 }
174
175 template< class InputIt >
177 InputIt first, InputIt last )
178 {
179 if constexpr (ThreadSafe) {
181 return super::insert(pos, first, last);
182 }
183
185 return super::insert(pos, first, last);
186 }
187
188 iterator insert( const_iterator pos, std::initializer_list<T> ilist )
189 {
190 if constexpr (ThreadSafe) {
192 return super::insert(pos, ilist);
193 }
194
196 return super::insert(pos, ilist);
197 }
198
199 template< class... Args >
200 iterator emplace( const_iterator pos, Args&&... args )
201 {
202 if constexpr (ThreadSafe) {
204 return super::emplace(pos, args...);
205 }
206
208 return super::emplace(pos, args...);
209 }
210
212 {
213 if constexpr (ThreadSafe) {
215 return super::erase(pos);
216 }
217
219 return super::erase(pos);
220 }
221
223 {
224 if constexpr (ThreadSafe) {
226 return super::erase(first, last);
227 }
228
230 return super::erase(first, last);
231 }
232
233 void push_back( const T& value )
234 {
235 if constexpr (ThreadSafe)
236 {
238 super::push_back(value);
239 }
240 else
241 {
243 super::push_back(value);
244 }
245 }
246
247 void push_back( T&& value )
248 {
249 if constexpr (ThreadSafe)
250 {
252 super::push_back(value);
253 }
254 else
255 {
257 super::push_back(value);
258 }
259 }
260
261 template< class... Args >
262 reference emplace_back( Args&&... args )
263 {
264 if constexpr (ThreadSafe) {
266 return super::emplace_back(args...);
267 }
268
270 return super::emplace_back(args...);
271 }
272
273 void pop_back()
274 {
275 if constexpr (ThreadSafe)
276 {
278 super::pop_back();
279 }
280 else
281 {
283 super::pop_back();
284 }
285 }
286
287 void resize( size_type count )
288 {
289 if constexpr (ThreadSafe)
290 {
292 super::resize(count);
293 }
294 else
295 {
297 super::resize(count);
298 }
299 }
300
301 void resize( size_type count, const value_type& value )
302 {
303 if constexpr (ThreadSafe)
304 {
306 super::resize(count, value);
307 }
308 else
309 {
311 super::resize(count, value);
312 }
313 }
314
315 void swap( vector& other ) noexcept
316 {
317 if constexpr (ThreadSafe)
318 {
320 super::swap(other); // Invalidates end() so must be protected.
321 }
322 else
323 {
325 super::swap(other); // Invalidates end() so must be protected.
326 }
327 }
328
329 std::size_t size() const
330 {
331 // Concurrent read/write on the size.
333 return super::size();
334 }
335};
336
337} // namespace atermpp
338#endif // MCRL2_ATERMPP_STANDARD_CONTAINER_VECTOR_H
mcrl2::utilities::lock_guard lock()
Acquire an exclusive lock.
mcrl2::utilities::shared_guard lock_shared()
Acquire a shared lock on this thread aterm pool.
A vector class in which aterms can be stored.
Definition vector.h:34
std::size_t size() const
Definition vector.h:329
iterator insert(const_iterator pos, InputIt first, InputIt last)
Definition vector.h:176
vector & operator=(const vector &x)=default
Assignment operator.
iterator insert(const_iterator pos, std::initializer_list< T > ilist)
Definition vector.h:188
vector & operator=(vector &&x)=default
Move assignment operator.
iterator insert(const_iterator pos, T &&value)
Definition vector.h:153
~vector()
Standard destructor.
Definition vector.h:116
void swap(vector &other) noexcept
Definition vector.h:315
super::allocator_type allocator_type
Standard typedefs.
Definition vector.h:42
iterator emplace(const_iterator pos, Args &&... args)
Definition vector.h:200
void push_back(const T &value)
Definition vector.h:233
iterator insert(const_iterator pos, size_type count, const T &value)
Definition vector.h:164
super::reference reference
Definition vector.h:45
vector(const vector &x, const allocator_type &alloc)
Constructor.
Definition vector.h:86
void push_back(T &&value)
Definition vector.h:247
super::value_type value_type
Definition vector.h:43
super::iterator iterator
Definition vector.h:46
vector(vector &&x)
Constructor.
Definition vector.h:92
iterator erase(const_iterator first, const_iterator last)
Definition vector.h:222
vector(const allocator_type &alloc)
Constructor.
Definition vector.h:56
void resize(size_type count, const value_type &value)
Definition vector.h:301
vector(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor.
Definition vector.h:74
void shrink_to_fit()
Definition vector.h:118
super::const_iterator const_iterator
Definition vector.h:47
super::size_type size_type
Definition vector.h:44
vector(vector &&x, const allocator_type &alloc)
Constructor.
Definition vector.h:98
vector(size_type n, const allocator_type &alloc=allocator_type())
Constructor.
Definition vector.h:62
iterator erase(const_iterator pos)
Definition vector.h:211
iterator insert(const_iterator pos, const T &value)
Definition vector.h:140
vector(const vector &x)
Constructor.
Definition vector.h:80
void resize(size_type count)
Definition vector.h:287
detail::generic_aterm_container< std::vector< detail::reference_aterm< T >, Alloc > > container_wrapper
Definition vector.h:38
void clear() noexcept
Definition vector.h:129
void pop_back()
Definition vector.h:273
reference emplace_back(Args &&... args)
Definition vector.h:262
vector(std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
Constructor. To be done later....
Definition vector.h:104
vector()
Default constructor.
Definition vector.h:50
std::vector< detail::reference_aterm< T >, Alloc > super
Definition vector.h:36
vector(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
Definition vector.h:67
An exclusive lock guard for the shared_mutex.
A shared lock guard for the shared_mutex.
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
The main namespace for the aterm++ library.
Definition algorithm.h:21
STL namespace.