]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container/static_vector.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / container / static_vector.hpp
1 // Boost.Container static_vector
2 //
3 // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
4 // Copyright (c) 2011-2013 Andrew Hundt.
5 // Copyright (c) 2013-2014 Ion Gaztanaga
6 //
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_CONTAINER_STATIC_VECTOR_HPP
12 #define BOOST_CONTAINER_STATIC_VECTOR_HPP
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/container/detail/type_traits.hpp>
25 #include <boost/container/vector.hpp>
26
27 #include <cstddef>
28 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
29 #include <initializer_list>
30 #endif
31
32 namespace boost { namespace container {
33
34 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
35
36 namespace container_detail {
37
38 template<class T, std::size_t N>
39 class static_storage_allocator
40 {
41 public:
42 typedef T value_type;
43
44 BOOST_CONTAINER_FORCEINLINE static_storage_allocator() BOOST_NOEXCEPT_OR_NOTHROW
45 {}
46
47 BOOST_CONTAINER_FORCEINLINE static_storage_allocator(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
48 {}
49
50 BOOST_CONTAINER_FORCEINLINE static_storage_allocator & operator=(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
51 { return *this; }
52
53 BOOST_CONTAINER_FORCEINLINE T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW
54 { return const_cast<T*>(static_cast<const T*>(static_cast<const void*>(&storage))); }
55
56 BOOST_CONTAINER_FORCEINLINE T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW
57 { return static_cast<T*>(static_cast<void*>(&storage)); }
58
59 static const std::size_t internal_capacity = N;
60
61 std::size_t max_size() const
62 { return N; }
63
64 typedef boost::container::container_detail::version_type<static_storage_allocator, 0> version;
65
66 BOOST_CONTAINER_FORCEINLINE friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
67 { return false; }
68
69 BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
70 { return true; }
71
72 private:
73 typename aligned_storage<sizeof(T)*N, alignment_of<T>::value>::type storage;
74 };
75
76 } //namespace container_detail {
77
78 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
79
80 //!
81 //!@brief A variable-size array container with fixed capacity.
82 //!
83 //!static_vector is a sequence container like boost::container::vector with contiguous storage that can
84 //!change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
85 //!
86 //!A static_vector is a sequence that supports random access to elements, constant time insertion and
87 //!removal of elements at the end, and linear time insertion and removal of elements at the beginning or
88 //!in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity
89 //!because elements are stored within the object itself similarly to an array. However, objects are
90 //!initialized as they are inserted into static_vector unlike C arrays or std::array which must construct
91 //!all elements on instantiation. The behavior of static_vector enables the use of statically allocated
92 //!elements in cases with complex object lifetime requirements that would otherwise not be trivially
93 //!possible.
94 //!
95 //!@par Error Handling
96 //! Insertion beyond the capacity result in throwing std::bad_alloc() if exceptions are enabled or
97 //! calling throw_bad_alloc() if not enabled.
98 //!
99 //! std::out_of_range is thrown if out of bound access is performed in <code>at()</code> if exceptions are
100 //! enabled, throw_out_of_range() if not enabled.
101 //!
102 //!@tparam Value The type of element that will be stored.
103 //!@tparam Capacity The maximum number of elements static_vector can store, fixed at compile time.
104 template <typename Value, std::size_t Capacity>
105 class static_vector
106 : public vector<Value, container_detail::static_storage_allocator<Value, Capacity> >
107 {
108 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
109 typedef vector<Value, container_detail::static_storage_allocator<Value, Capacity> > base_t;
110
111 BOOST_COPYABLE_AND_MOVABLE(static_vector)
112
113 template<class U, std::size_t OtherCapacity>
114 friend class static_vector;
115
116 public:
117 typedef container_detail::static_storage_allocator<Value, Capacity> allocator_type;
118 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
119
120 public:
121 //! @brief The type of elements stored in the container.
122 typedef typename base_t::value_type value_type;
123 //! @brief The unsigned integral type used by the container.
124 typedef typename base_t::size_type size_type;
125 //! @brief The pointers difference type.
126 typedef typename base_t::difference_type difference_type;
127 //! @brief The pointer type.
128 typedef typename base_t::pointer pointer;
129 //! @brief The const pointer type.
130 typedef typename base_t::const_pointer const_pointer;
131 //! @brief The value reference type.
132 typedef typename base_t::reference reference;
133 //! @brief The value const reference type.
134 typedef typename base_t::const_reference const_reference;
135 //! @brief The iterator type.
136 typedef typename base_t::iterator iterator;
137 //! @brief The const iterator type.
138 typedef typename base_t::const_iterator const_iterator;
139 //! @brief The reverse iterator type.
140 typedef typename base_t::reverse_iterator reverse_iterator;
141 //! @brief The const reverse iterator.
142 typedef typename base_t::const_reverse_iterator const_reverse_iterator;
143
144 //! @brief The capacity/max size of the container
145 static const size_type static_capacity = Capacity;
146
147 //! @brief Constructs an empty static_vector.
148 //!
149 //! @par Throws
150 //! Nothing.
151 //!
152 //! @par Complexity
153 //! Constant O(1).
154 BOOST_CONTAINER_FORCEINLINE static_vector() BOOST_NOEXCEPT_OR_NOTHROW
155 : base_t()
156 {}
157
158 //! @pre <tt>count <= capacity()</tt>
159 //!
160 //! @brief Constructs a static_vector containing count value initialized values.
161 //!
162 //! @param count The number of values which will be contained in the container.
163 //!
164 //! @par Throws
165 //! If Value's value initialization throws.
166 //!
167 //! @par Complexity
168 //! Linear O(N).
169 BOOST_CONTAINER_FORCEINLINE explicit static_vector(size_type count)
170 : base_t(count)
171 {}
172
173 //! @pre <tt>count <= capacity()</tt>
174 //!
175 //! @brief Constructs a static_vector containing count default initialized values.
176 //!
177 //! @param count The number of values which will be contained in the container.
178 //!
179 //! @par Throws
180 //! If Value's default initialization throws.
181 //!
182 //! @par Complexity
183 //! Linear O(N).
184 //!
185 //! @par Note
186 //! Non-standard extension
187 BOOST_CONTAINER_FORCEINLINE static_vector(size_type count, default_init_t)
188 : base_t(count, default_init_t())
189 {}
190
191 //! @pre <tt>count <= capacity()</tt>
192 //!
193 //! @brief Constructs a static_vector containing count copies of value.
194 //!
195 //! @param count The number of copies of a values that will be contained in the container.
196 //! @param value The value which will be used to copy construct values.
197 //!
198 //! @par Throws
199 //! If Value's copy constructor throws.
200 //!
201 //! @par Complexity
202 //! Linear O(N).
203 BOOST_CONTAINER_FORCEINLINE static_vector(size_type count, value_type const& value)
204 : base_t(count, value)
205 {}
206
207 //! @pre
208 //! @li <tt>distance(first, last) <= capacity()</tt>
209 //! @li Iterator must meet the \c ForwardTraversalIterator concept.
210 //!
211 //! @brief Constructs a static_vector containing copy of a range <tt>[first, last)</tt>.
212 //!
213 //! @param first The iterator to the first element in range.
214 //! @param last The iterator to the one after the last element in range.
215 //!
216 //! @par Throws
217 //! If Value's constructor taking a dereferenced Iterator throws.
218 //!
219 //! @par Complexity
220 //! Linear O(N).
221 template <typename Iterator>
222 BOOST_CONTAINER_FORCEINLINE static_vector(Iterator first, Iterator last)
223 : base_t(first, last)
224 {}
225
226 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
227 //! @pre
228 //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
229 //!
230 //! @brief Constructs a static_vector containing copy of a range <tt>[il.begin(), il.end())</tt>.
231 //!
232 //! @param il std::initializer_list with values to initialize vector.
233 //!
234 //! @par Throws
235 //! If Value's constructor taking a dereferenced std::initializer_list throws.
236 //!
237 //! @par Complexity
238 //! Linear O(N).
239 BOOST_CONTAINER_FORCEINLINE static_vector(std::initializer_list<value_type> il)
240 : base_t(il)
241 {}
242 #endif
243
244 //! @brief Constructs a copy of other static_vector.
245 //!
246 //! @param other The static_vector which content will be copied to this one.
247 //!
248 //! @par Throws
249 //! If Value's copy constructor throws.
250 //!
251 //! @par Complexity
252 //! Linear O(N).
253 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector const& other)
254 : base_t(other)
255 {}
256
257 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector const& other, const allocator_type &)
258 : base_t(other)
259 {}
260
261 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF(static_vector) other, const allocator_type &)
262 BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<value_type>::value)
263 : base_t(BOOST_MOVE_BASE(base_t, other))
264 {}
265
266 BOOST_CONTAINER_FORCEINLINE explicit static_vector(const allocator_type &)
267 : base_t()
268 {}
269
270 //! @pre <tt>other.size() <= capacity()</tt>.
271 //!
272 //! @brief Constructs a copy of other static_vector.
273 //!
274 //! @param other The static_vector which content will be copied to this one.
275 //!
276 //! @par Throws
277 //! If Value's copy constructor throws.
278 //!
279 //! @par Complexity
280 //! Linear O(N).
281 template <std::size_t C>
282 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector<value_type, C> const& other)
283 : base_t(other)
284 {}
285
286 //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
287 //!
288 //! @param other The static_vector which content will be moved to this one.
289 //!
290 //! @par Throws
291 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
292 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
293 //!
294 //! @par Complexity
295 //! Linear O(N).
296 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF(static_vector) other)
297 BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<value_type>::value)
298 : base_t(BOOST_MOVE_BASE(base_t, other))
299 {}
300
301 //! @pre <tt>other.size() <= capacity()</tt>
302 //!
303 //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
304 //!
305 //! @param other The static_vector which content will be moved to this one.
306 //!
307 //! @par Throws
308 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
309 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
310 //!
311 //! @par Complexity
312 //! Linear O(N).
313 template <std::size_t C>
314 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF_BEG static_vector<value_type, C> BOOST_RV_REF_END other)
315 : base_t(BOOST_MOVE_BASE(typename static_vector<value_type BOOST_MOVE_I C>::base_t, other))
316 {}
317
318 //! @brief Copy assigns Values stored in the other static_vector to this one.
319 //!
320 //! @param other The static_vector which content will be copied to this one.
321 //!
322 //! @par Throws
323 //! If Value's copy constructor or copy assignment throws.
324 //!
325 //! @par Complexity
326 //! Linear O(N).
327 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_COPY_ASSIGN_REF(static_vector) other)
328 {
329 return static_cast<static_vector&>(base_t::operator=(static_cast<base_t const&>(other)));
330 }
331
332 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
333 //! @brief Copy assigns Values stored in std::initializer_list to *this.
334 //!
335 //! @param il The std::initializer_list which content will be copied to this one.
336 //!
337 //! @par Throws
338 //! If Value's copy constructor or copy assignment throws.
339 //!
340 //! @par Complexity
341 //! Linear O(N).
342 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(std::initializer_list<value_type> il)
343 { return static_cast<static_vector&>(base_t::operator=(il)); }
344 #endif
345
346 //! @pre <tt>other.size() <= capacity()</tt>
347 //!
348 //! @brief Copy assigns Values stored in the other static_vector to this one.
349 //!
350 //! @param other The static_vector which content will be copied to this one.
351 //!
352 //! @par Throws
353 //! If Value's copy constructor or copy assignment throws.
354 //!
355 //! @par Complexity
356 //! Linear O(N).
357 template <std::size_t C>
358 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(static_vector<value_type, C> const& other)
359 {
360 return static_cast<static_vector&>(base_t::operator=
361 (static_cast<typename static_vector<value_type, C>::base_t const&>(other)));
362 }
363
364 //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
365 //!
366 //! @param other The static_vector which content will be moved to this one.
367 //!
368 //! @par Throws
369 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
370 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
371 //!
372 //! @par Complexity
373 //! Linear O(N).
374 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_RV_REF(static_vector) other)
375 {
376 return static_cast<static_vector&>(base_t::operator=(BOOST_MOVE_BASE(base_t, other)));
377 }
378
379 //! @pre <tt>other.size() <= capacity()</tt>
380 //!
381 //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
382 //!
383 //! @param other The static_vector which content will be moved to this one.
384 //!
385 //! @par Throws
386 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
387 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
388 //!
389 //! @par Complexity
390 //! Linear O(N).
391 template <std::size_t C>
392 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_RV_REF_BEG static_vector<value_type, C> BOOST_RV_REF_END other)
393 {
394 return static_cast<static_vector&>(base_t::operator=
395 (BOOST_MOVE_BASE(typename static_vector<value_type BOOST_MOVE_I C>::base_t, other)));
396 }
397
398 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
399
400 //! @brief Destructor. Destroys Values stored in this container.
401 //!
402 //! @par Throws
403 //! Nothing
404 //!
405 //! @par Complexity
406 //! Linear O(N).
407 ~static_vector();
408
409 //! @brief Swaps contents of the other static_vector and this one.
410 //!
411 //! @param other The static_vector which content will be swapped with this one's content.
412 //!
413 //! @par Throws
414 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
415 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
416 //!
417 //! @par Complexity
418 //! Linear O(N).
419 void swap(static_vector & other);
420
421 //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
422 //!
423 //! @brief Swaps contents of the other static_vector and this one.
424 //!
425 //! @param other The static_vector which content will be swapped with this one's content.
426 //!
427 //! @par Throws
428 //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
429 //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
430 //!
431 //! @par Complexity
432 //! Linear O(N).
433 template <std::size_t C>
434 void swap(static_vector<value_type, C> & other);
435
436 //! @pre <tt>count <= capacity()</tt>
437 //!
438 //! @brief Inserts or erases elements at the end such that
439 //! the size becomes count. New elements are value initialized.
440 //!
441 //! @param count The number of elements which will be stored in the container.
442 //!
443 //! @par Throws
444 //! If Value's value initialization throws.
445 //!
446 //! @par Complexity
447 //! Linear O(N).
448 void resize(size_type count);
449
450 //! @pre <tt>count <= capacity()</tt>
451 //!
452 //! @brief Inserts or erases elements at the end such that
453 //! the size becomes count. New elements are default initialized.
454 //!
455 //! @param count The number of elements which will be stored in the container.
456 //!
457 //! @par Throws
458 //! If Value's default initialization throws.
459 //!
460 //! @par Complexity
461 //! Linear O(N).
462 //!
463 //! @par Note
464 //! Non-standard extension
465 void resize(size_type count, default_init_t);
466
467 //! @pre <tt>count <= capacity()</tt>
468 //!
469 //! @brief Inserts or erases elements at the end such that
470 //! the size becomes count. New elements are copy constructed from value.
471 //!
472 //! @param count The number of elements which will be stored in the container.
473 //! @param value The value used to copy construct the new element.
474 //!
475 //! @par Throws
476 //! If Value's copy constructor throws.
477 //!
478 //! @par Complexity
479 //! Linear O(N).
480 void resize(size_type count, value_type const& value);
481
482 //! @pre <tt>count <= capacity()</tt>
483 //!
484 //! @brief This call has no effect because the Capacity of this container is constant.
485 //!
486 //! @param count The number of elements which the container should be able to contain.
487 //!
488 //! @par Throws
489 //! Nothing.
490 //!
491 //! @par Complexity
492 //! Linear O(N).
493 void reserve(size_type count) BOOST_NOEXCEPT_OR_NOTHROW;
494
495 //! @pre <tt>size() < capacity()</tt>
496 //!
497 //! @brief Adds a copy of value at the end.
498 //!
499 //! @param value The value used to copy construct the new element.
500 //!
501 //! @par Throws
502 //! If Value's copy constructor throws.
503 //!
504 //! @par Complexity
505 //! Constant O(1).
506 void push_back(value_type const& value);
507
508 //! @pre <tt>size() < capacity()</tt>
509 //!
510 //! @brief Moves value to the end.
511 //!
512 //! @param value The value to move construct the new element.
513 //!
514 //! @par Throws
515 //! If Value's move constructor throws.
516 //!
517 //! @par Complexity
518 //! Constant O(1).
519 void push_back(BOOST_RV_REF(value_type) value);
520
521 //! @pre <tt>!empty()</tt>
522 //!
523 //! @brief Destroys last value and decreases the size.
524 //!
525 //! @par Throws
526 //! Nothing by default.
527 //!
528 //! @par Complexity
529 //! Constant O(1).
530 void pop_back();
531
532 //! @pre
533 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
534 //! @li <tt>size() < capacity()</tt>
535 //!
536 //! @brief Inserts a copy of element at p.
537 //!
538 //! @param p The position at which the new value will be inserted.
539 //! @param value The value used to copy construct the new element.
540 //!
541 //! @par Throws
542 //! @li If Value's copy constructor or copy assignment throws
543 //! @li If Value's move constructor or move assignment throws.
544 //!
545 //! @par Complexity
546 //! Constant or linear.
547 iterator insert(const_iterator p, value_type const& value);
548
549 //! @pre
550 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
551 //! @li <tt>size() < capacity()</tt>
552 //!
553 //! @brief Inserts a move-constructed element at p.
554 //!
555 //! @param p The position at which the new value will be inserted.
556 //! @param value The value used to move construct the new element.
557 //!
558 //! @par Throws
559 //! If Value's move constructor or move assignment throws.
560 //!
561 //! @par Complexity
562 //! Constant or linear.
563 iterator insert(const_iterator p, BOOST_RV_REF(value_type) value);
564
565 //! @pre
566 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
567 //! @li <tt>size() + count <= capacity()</tt>
568 //!
569 //! @brief Inserts a count copies of value at p.
570 //!
571 //! @param p The position at which new elements will be inserted.
572 //! @param count The number of new elements which will be inserted.
573 //! @param value The value used to copy construct new elements.
574 //!
575 //! @par Throws
576 //! @li If Value's copy constructor or copy assignment throws.
577 //! @li If Value's move constructor or move assignment throws.
578 //!
579 //! @par Complexity
580 //! Linear O(N).
581 iterator insert(const_iterator p, size_type count, value_type const& value);
582
583 //! @pre
584 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
585 //! @li <tt>distance(first, last) <= capacity()</tt>
586 //! @li \c Iterator must meet the \c ForwardTraversalIterator concept.
587 //!
588 //! @brief Inserts a copy of a range <tt>[first, last)</tt> at p.
589 //!
590 //! @param p The position at which new elements will be inserted.
591 //! @param first The iterator to the first element of a range used to construct new elements.
592 //! @param last The iterator to the one after the last element of a range used to construct new elements.
593 //!
594 //! @par Throws
595 //! @li If Value's constructor and assignment taking a dereferenced \c Iterator.
596 //! @li If Value's move constructor or move assignment throws.
597 //!
598 //! @par Complexity
599 //! Linear O(N).
600 template <typename Iterator>
601 iterator insert(const_iterator p, Iterator first, Iterator last);
602
603 //! @pre
604 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
605 //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
606 //!
607 //! @brief Inserts a copy of a range <tt>[il.begin(), il.end())</tt> at p.
608 //!
609 //! @param p The position at which new elements will be inserted.
610 //! @param il The std::initializer_list which contains elements that will be inserted.
611 //!
612 //! @par Throws
613 //! @li If Value's constructor and assignment taking a dereferenced std::initializer_list iterator.
614 //!
615 //! @par Complexity
616 //! Linear O(N).
617 iterator insert(const_iterator p, std::initializer_list<value_type> il);
618
619 //! @pre \c p must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
620 //!
621 //! @brief Erases Value from p.
622 //!
623 //! @param p The position of the element which will be erased from the container.
624 //!
625 //! @par Throws
626 //! If Value's move assignment throws.
627 //!
628 //! @par Complexity
629 //! Linear O(N).
630 iterator erase(const_iterator p);
631
632 //! @pre
633 //! @li \c first and \c last must define a valid range
634 //! @li iterators must be in range <tt>[begin(), end()]</tt>
635 //!
636 //! @brief Erases Values from a range <tt>[first, last)</tt>.
637 //!
638 //! @param first The position of the first element of a range which will be erased from the container.
639 //! @param last The position of the one after the last element of a range which will be erased from the container.
640 //!
641 //! @par Throws
642 //! If Value's move assignment throws.
643 //!
644 //! @par Complexity
645 //! Linear O(N).
646 iterator erase(const_iterator first, const_iterator last);
647
648 //! @pre <tt>distance(first, last) <= capacity()</tt>
649 //!
650 //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
651 //!
652 //! @param first The iterator to the first element of a range used to construct new content of this container.
653 //! @param last The iterator to the one after the last element of a range used to construct new content of this container.
654 //!
655 //! @par Throws
656 //! If Value's copy constructor or copy assignment throws,
657 //!
658 //! @par Complexity
659 //! Linear O(N).
660 template <typename Iterator>
661 void assign(Iterator first, Iterator last);
662
663 //! @pre <tt>distance(il.begin(), il.end()) <= capacity()</tt>
664 //!
665 //! @brief Assigns a range <tt>[il.begin(), il.end())</tt> of Values to this container.
666 //!
667 //! @param il std::initializer_list with values used to construct new content of this container.
668 //!
669 //! @par Throws
670 //! If Value's copy constructor or copy assignment throws,
671 //!
672 //! @par Complexity
673 //! Linear O(N).
674 void assign(std::initializer_list<value_type> il);
675
676 //! @pre <tt>count <= capacity()</tt>
677 //!
678 //! @brief Assigns a count copies of value to this container.
679 //!
680 //! @param count The new number of elements which will be container in the container.
681 //! @param value The value which will be used to copy construct the new content.
682 //!
683 //! @par Throws
684 //! If Value's copy constructor or copy assignment throws.
685 //!
686 //! @par Complexity
687 //! Linear O(N).
688 void assign(size_type count, value_type const& value);
689
690 //! @pre <tt>size() < capacity()</tt>
691 //!
692 //! @brief Inserts a Value constructed with
693 //! \c std::forward<Args>(args)... in the end of the container.
694 //!
695 //! @return A reference to the created object.
696 //!
697 //! @param args The arguments of the constructor of the new element which will be created at the end of the container.
698 //!
699 //! @par Throws
700 //! If in-place constructor throws or Value's move constructor throws.
701 //!
702 //! @par Complexity
703 //! Constant O(1).
704 template<class ...Args>
705 reference emplace_back(Args &&...args);
706
707 //! @pre
708 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
709 //! @li <tt>size() < capacity()</tt>
710 //!
711 //! @brief Inserts a Value constructed with
712 //! \c std::forward<Args>(args)... before p
713 //!
714 //! @param p The position at which new elements will be inserted.
715 //! @param args The arguments of the constructor of the new element.
716 //!
717 //! @par Throws
718 //! If in-place constructor throws or if Value's move constructor or move assignment throws.
719 //!
720 //! @par Complexity
721 //! Constant or linear.
722 template<class ...Args>
723 iterator emplace(const_iterator p, Args &&...args);
724
725 //! @brief Removes all elements from the container.
726 //!
727 //! @par Throws
728 //! Nothing.
729 //!
730 //! @par Complexity
731 //! Constant O(1).
732 void clear() BOOST_NOEXCEPT_OR_NOTHROW;
733
734 //! @pre <tt>i < size()</tt>
735 //!
736 //! @brief Returns reference to the i-th element.
737 //!
738 //! @param i The element's index.
739 //!
740 //! @return reference to the i-th element
741 //! from the beginning of the container.
742 //!
743 //! @par Throws
744 //! \c std::out_of_range exception by default.
745 //!
746 //! @par Complexity
747 //! Constant O(1).
748 reference at(size_type i);
749
750 //! @pre <tt>i < size()</tt>
751 //!
752 //! @brief Returns const reference to the i-th element.
753 //!
754 //! @param i The element's index.
755 //!
756 //! @return const reference to the i-th element
757 //! from the beginning of the container.
758 //!
759 //! @par Throws
760 //! \c std::out_of_range exception by default.
761 //!
762 //! @par Complexity
763 //! Constant O(1).
764 const_reference at(size_type i) const;
765
766 //! @pre <tt>i < size()</tt>
767 //!
768 //! @brief Returns reference to the i-th element.
769 //!
770 //! @param i The element's index.
771 //!
772 //! @return reference to the i-th element
773 //! from the beginning of the container.
774 //!
775 //! @par Throws
776 //! Nothing by default.
777 //!
778 //! @par Complexity
779 //! Constant O(1).
780 reference operator[](size_type i);
781
782 //! @pre <tt>i < size()</tt>
783 //!
784 //! @brief Returns const reference to the i-th element.
785 //!
786 //! @param i The element's index.
787 //!
788 //! @return const reference to the i-th element
789 //! from the beginning of the container.
790 //!
791 //! @par Throws
792 //! Nothing by default.
793 //!
794 //! @par Complexity
795 //! Constant O(1).
796 const_reference operator[](size_type i) const;
797
798 //! @pre <tt>i =< size()</tt>
799 //!
800 //! @brief Returns a iterator to the i-th element.
801 //!
802 //! @param i The element's index.
803 //!
804 //! @return a iterator to the i-th element.
805 //!
806 //! @par Throws
807 //! Nothing by default.
808 //!
809 //! @par Complexity
810 //! Constant O(1).
811 iterator nth(size_type i);
812
813 //! @pre <tt>i =< size()</tt>
814 //!
815 //! @brief Returns a const_iterator to the i-th element.
816 //!
817 //! @param i The element's index.
818 //!
819 //! @return a const_iterator to the i-th element.
820 //!
821 //! @par Throws
822 //! Nothing by default.
823 //!
824 //! @par Complexity
825 //! Constant O(1).
826 const_iterator nth(size_type i) const;
827
828 //! @pre <tt>begin() <= p <= end()</tt>
829 //!
830 //! @brief Returns the index of the element pointed by p.
831 //!
832 //! @param p An iterator to the element.
833 //!
834 //! @return The index of the element pointed by p.
835 //!
836 //! @par Throws
837 //! Nothing by default.
838 //!
839 //! @par Complexity
840 //! Constant O(1).
841 size_type index_of(iterator p);
842
843 //! @pre <tt>begin() <= p <= end()</tt>
844 //!
845 //! @brief Returns the index of the element pointed by p.
846 //!
847 //! @param p A const_iterator to the element.
848 //!
849 //! @return a const_iterator to the i-th element.
850 //!
851 //! @par Throws
852 //! Nothing by default.
853 //!
854 //! @par Complexity
855 //! Constant O(1).
856 size_type index_of(const_iterator p) const;
857
858 //! @pre \c !empty()
859 //!
860 //! @brief Returns reference to the first element.
861 //!
862 //! @return reference to the first element
863 //! from the beginning of the container.
864 //!
865 //! @par Throws
866 //! Nothing by default.
867 //!
868 //! @par Complexity
869 //! Constant O(1).
870 reference front();
871
872 //! @pre \c !empty()
873 //!
874 //! @brief Returns const reference to the first element.
875 //!
876 //! @return const reference to the first element
877 //! from the beginning of the container.
878 //!
879 //! @par Throws
880 //! Nothing by default.
881 //!
882 //! @par Complexity
883 //! Constant O(1).
884 const_reference front() const;
885
886 //! @pre \c !empty()
887 //!
888 //! @brief Returns reference to the last element.
889 //!
890 //! @return reference to the last element
891 //! from the beginning of the container.
892 //!
893 //! @par Throws
894 //! Nothing by default.
895 //!
896 //! @par Complexity
897 //! Constant O(1).
898 reference back();
899
900 //! @pre \c !empty()
901 //!
902 //! @brief Returns const reference to the first element.
903 //!
904 //! @return const reference to the last element
905 //! from the beginning of the container.
906 //!
907 //! @par Throws
908 //! Nothing by default.
909 //!
910 //! @par Complexity
911 //! Constant O(1).
912 const_reference back() const;
913
914 //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
915 //! For a non-empty vector <tt>data() == &front()</tt>.
916 //!
917 //! @par Throws
918 //! Nothing.
919 //!
920 //! @par Complexity
921 //! Constant O(1).
922 Value * data() BOOST_NOEXCEPT_OR_NOTHROW;
923
924 //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
925 //! For a non-empty vector <tt>data() == &front()</tt>.
926 //!
927 //! @par Throws
928 //! Nothing.
929 //!
930 //! @par Complexity
931 //! Constant O(1).
932 const Value * data() const BOOST_NOEXCEPT_OR_NOTHROW;
933
934 //! @brief Returns iterator to the first element.
935 //!
936 //! @return iterator to the first element contained in the vector.
937 //!
938 //! @par Throws
939 //! Nothing.
940 //!
941 //! @par Complexity
942 //! Constant O(1).
943 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
944
945 //! @brief Returns const iterator to the first element.
946 //!
947 //! @return const_iterator to the first element contained in the vector.
948 //!
949 //! @par Throws
950 //! Nothing.
951 //!
952 //! @par Complexity
953 //! Constant O(1).
954 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
955
956 //! @brief Returns const iterator to the first element.
957 //!
958 //! @return const_iterator to the first element contained in the vector.
959 //!
960 //! @par Throws
961 //! Nothing.
962 //!
963 //! @par Complexity
964 //! Constant O(1).
965 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
966
967 //! @brief Returns iterator to the one after the last element.
968 //!
969 //! @return iterator pointing to the one after the last element contained in the vector.
970 //!
971 //! @par Throws
972 //! Nothing.
973 //!
974 //! @par Complexity
975 //! Constant O(1).
976 iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
977
978 //! @brief Returns const iterator to the one after the last element.
979 //!
980 //! @return const_iterator pointing to the one after the last element contained in the vector.
981 //!
982 //! @par Throws
983 //! Nothing.
984 //!
985 //! @par Complexity
986 //! Constant O(1).
987 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
988
989 //! @brief Returns const iterator to the one after the last element.
990 //!
991 //! @return const_iterator pointing to the one after the last element contained in the vector.
992 //!
993 //! @par Throws
994 //! Nothing.
995 //!
996 //! @par Complexity
997 //! Constant O(1).
998 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
999
1000 //! @brief Returns reverse iterator to the first element of the reversed container.
1001 //!
1002 //! @return reverse_iterator pointing to the beginning
1003 //! of the reversed static_vector.
1004 //!
1005 //! @par Throws
1006 //! Nothing.
1007 //!
1008 //! @par Complexity
1009 //! Constant O(1).
1010 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
1011
1012 //! @brief Returns const reverse iterator to the first element of the reversed container.
1013 //!
1014 //! @return const_reverse_iterator pointing to the beginning
1015 //! of the reversed static_vector.
1016 //!
1017 //! @par Throws
1018 //! Nothing.
1019 //!
1020 //! @par Complexity
1021 //! Constant O(1).
1022 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1023
1024 //! @brief Returns const reverse iterator to the first element of the reversed container.
1025 //!
1026 //! @return const_reverse_iterator pointing to the beginning
1027 //! of the reversed static_vector.
1028 //!
1029 //! @par Throws
1030 //! Nothing.
1031 //!
1032 //! @par Complexity
1033 //! Constant O(1).
1034 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1035
1036 //! @brief Returns reverse iterator to the one after the last element of the reversed container.
1037 //!
1038 //! @return reverse_iterator pointing to the one after the last element
1039 //! of the reversed static_vector.
1040 //!
1041 //! @par Throws
1042 //! Nothing.
1043 //!
1044 //! @par Complexity
1045 //! Constant O(1).
1046 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
1047
1048 //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
1049 //!
1050 //! @return const_reverse_iterator pointing to the one after the last element
1051 //! of the reversed static_vector.
1052 //!
1053 //! @par Throws
1054 //! Nothing.
1055 //!
1056 //! @par Complexity
1057 //! Constant O(1).
1058 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
1059
1060 //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
1061 //!
1062 //! @return const_reverse_iterator pointing to the one after the last element
1063 //! of the reversed static_vector.
1064 //!
1065 //! @par Throws
1066 //! Nothing.
1067 //!
1068 //! @par Complexity
1069 //! Constant O(1).
1070 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
1071
1072 //! @brief Returns container's capacity.
1073 //!
1074 //! @return container's capacity.
1075 //!
1076 //! @par Throws
1077 //! Nothing.
1078 //!
1079 //! @par Complexity
1080 //! Constant O(1).
1081 static size_type capacity() BOOST_NOEXCEPT_OR_NOTHROW;
1082
1083 //! @brief Returns container's capacity.
1084 //!
1085 //! @return container's capacity.
1086 //!
1087 //! @par Throws
1088 //! Nothing.
1089 //!
1090 //! @par Complexity
1091 //! Constant O(1).
1092 static size_type max_size() BOOST_NOEXCEPT_OR_NOTHROW;
1093
1094 //! @brief Returns the number of stored elements.
1095 //!
1096 //! @return Number of elements contained in the container.
1097 //!
1098 //! @par Throws
1099 //! Nothing.
1100 //!
1101 //! @par Complexity
1102 //! Constant O(1).
1103 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
1104
1105 //! @brief Queries if the container contains elements.
1106 //!
1107 //! @return true if the number of elements contained in the
1108 //! container is equal to 0.
1109 //!
1110 //! @par Throws
1111 //! Nothing.
1112 //!
1113 //! @par Complexity
1114 //! Constant O(1).
1115 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
1116 #else
1117
1118 BOOST_CONTAINER_FORCEINLINE friend void swap(static_vector &x, static_vector &y)
1119 {
1120 x.swap(y);
1121 }
1122
1123 #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
1124
1125 };
1126
1127 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1128
1129 //! @brief Checks if contents of two static_vectors are equal.
1130 //!
1131 //! @ingroup static_vector_non_member
1132 //!
1133 //! @param x The first static_vector.
1134 //! @param y The second static_vector.
1135 //!
1136 //! @return \c true if containers have the same size and elements in both containers are equal.
1137 //!
1138 //! @par Complexity
1139 //! Linear O(N).
1140 template<typename V, std::size_t C1, std::size_t C2>
1141 bool operator== (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1142
1143 //! @brief Checks if contents of two static_vectors are not equal.
1144 //!
1145 //! @ingroup static_vector_non_member
1146 //!
1147 //! @param x The first static_vector.
1148 //! @param y The second static_vector.
1149 //!
1150 //! @return \c true if containers have different size or elements in both containers are not equal.
1151 //!
1152 //! @par Complexity
1153 //! Linear O(N).
1154 template<typename V, std::size_t C1, std::size_t C2>
1155 bool operator!= (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1156
1157 //! @brief Lexicographically compares static_vectors.
1158 //!
1159 //! @ingroup static_vector_non_member
1160 //!
1161 //! @param x The first static_vector.
1162 //! @param y The second static_vector.
1163 //!
1164 //! @return \c true if x compares lexicographically less than y.
1165 //!
1166 //! @par Complexity
1167 //! Linear O(N).
1168 template<typename V, std::size_t C1, std::size_t C2>
1169 bool operator< (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1170
1171 //! @brief Lexicographically compares static_vectors.
1172 //!
1173 //! @ingroup static_vector_non_member
1174 //!
1175 //! @param x The first static_vector.
1176 //! @param y The second static_vector.
1177 //!
1178 //! @return \c true if y compares lexicographically less than x.
1179 //!
1180 //! @par Complexity
1181 //! Linear O(N).
1182 template<typename V, std::size_t C1, std::size_t C2>
1183 bool operator> (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1184
1185 //! @brief Lexicographically compares static_vectors.
1186 //!
1187 //! @ingroup static_vector_non_member
1188 //!
1189 //! @param x The first static_vector.
1190 //! @param y The second static_vector.
1191 //!
1192 //! @return \c true if y don't compare lexicographically less than x.
1193 //!
1194 //! @par Complexity
1195 //! Linear O(N).
1196 template<typename V, std::size_t C1, std::size_t C2>
1197 bool operator<= (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1198
1199 //! @brief Lexicographically compares static_vectors.
1200 //!
1201 //! @ingroup static_vector_non_member
1202 //!
1203 //! @param x The first static_vector.
1204 //! @param y The second static_vector.
1205 //!
1206 //! @return \c true if x don't compare lexicographically less than y.
1207 //!
1208 //! @par Complexity
1209 //! Linear O(N).
1210 template<typename V, std::size_t C1, std::size_t C2>
1211 bool operator>= (static_vector<V, C1> const& x, static_vector<V, C2> const& y);
1212
1213 //! @brief Swaps contents of two static_vectors.
1214 //!
1215 //! This function calls static_vector::swap().
1216 //!
1217 //! @ingroup static_vector_non_member
1218 //!
1219 //! @param x The first static_vector.
1220 //! @param y The second static_vector.
1221 //!
1222 //! @par Complexity
1223 //! Linear O(N).
1224 template<typename V, std::size_t C1, std::size_t C2>
1225 inline void swap(static_vector<V, C1> & x, static_vector<V, C2> & y);
1226
1227 #else
1228
1229 template<typename V, std::size_t C1, std::size_t C2>
1230 inline void swap(static_vector<V, C1> & x, static_vector<V, C2> & y
1231 , typename container_detail::enable_if_c< C1 != C2>::type * = 0)
1232 {
1233 x.swap(y);
1234 }
1235
1236 #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
1237
1238 }} // namespace boost::container
1239
1240 #include <boost/container/detail/config_end.hpp>
1241
1242 #endif // BOOST_CONTAINER_STATIC_VECTOR_HPP