|
libbmb
Modern implementation of STL
|
AllocatorAware dynamic array structure. More...
#include <vector.h>
Public Types | |
| using | value_type = T |
| using | reference = value_type & |
| using | const_reference = const value_type & |
| using | pointer = value_type * |
| using | const_pointer = const value_type * |
| using | size_type = size_t |
| using | allocator_type = Allocator |
| using | iterator = detail::BaseVectorIter< T, false > |
| using | const_iterator = detail::BaseVectorIter< T, true > |
Friends | |
| void | swap (Vector &a, Vector &b) |
| Efficiently swaps data of the Vectors. | |
AllocatorAware dynamic array structure.
All methods provides strong/conditional exception safety.
Notes: Memory incrementation coefficient is hardcoded and equals 2. Probably, clients will be able to change it dynamically in future.
Current state notes: no support of insert in arbitrary place of the array. User provided type must not delete move constructor.
| using bmb::Vector< T, Allocator >::allocator_type = Allocator |
| using bmb::Vector< T, Allocator >::const_iterator = detail::BaseVectorIter<T, true> |
| using bmb::Vector< T, Allocator >::const_pointer = const value_type* |
| using bmb::Vector< T, Allocator >::const_reference = const value_type& |
| using bmb::Vector< T, Allocator >::iterator = detail::BaseVectorIter<T, false> |
| using bmb::Vector< T, Allocator >::pointer = value_type* |
| using bmb::Vector< T, Allocator >::reference = value_type& |
| using bmb::Vector< T, Allocator >::size_type = size_t |
| using bmb::Vector< T, Allocator >::value_type = T |
|
inlinenoexcept |
|
inlineexplicit |
|
inlineexplicit |
Constructs count elements with given value.
Allocates memory for exactly count elements. Then copies given value into count elements.
| count | Number of elements to construct |
| value | Value to initialize the array. Has default value |
| alloc | Container's allocator. Has default value |
| Provides | strong exception guarantee. If exception is thrown during coping the value - all constructed elements are destroyed, allocated memory is deallocated and the exception is rethrown. |
|
inline |
Initialize Vector with the given range.
Constructs Vector with elements equal to the ones in [first, last).
| first | Start of the range |
| last | End of the range |
| alloc | Container's allocator. Has default value |
| Provides | strong exception guarantee. If exception is thrown during coping the range's value - all constructed elements are destroyed, allocated memory is deallocated and the exception is rethrown. |
|
inline |
Initialize Vector with the given initializer_list.
Constructs Vector with elements equal to the ones in the initializer_list.
| init_list | Initializer list to copy |
| alloc | Container's allocator. Has default value |
| Provides | strong exception guarantee. If exception is thrown during coping the initializer_list's value - all constructed elements are destroyed, allocated memory is deallocated and the exception is rethrown. |
Copy constructor.
| Provides | strong exception guarantee. If exception is thrown during coping - all constructed elements are destroyed, allocated memory is deallocated and the exception is rethrown. |
|
inline |
|
inline |
Returns element at n-th index in the array. If index is out of bounds, throws std::out_of_range
|
inline |
Returns element at n-th index in the array. If index is out of bounds, throws std::out_of_range
|
inlinenoexcept |
Returns last element in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
Returns last element in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Destroyes the last object in the array.
The end() iterator is invalidated.
| Throws | std::logic_error if array is empty |
|
inlinenoexcept |
Returns current Vector's capacity.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Empties the Vector.
Destroyes all elements in the array and deallocate storage. All fields are nullified.
| noexcept |
|
inline |
Constructs new element from given args.
If array has memory for one more element - constructs an element at the end of the storage. Only end() iterator is invalidated.
If array is full - reallocates storage with the larger capacity and constructs an element there. All references and iterators are invalidated.
After this operation Vector's size is incremented by 1.
Time complexity: amortized O(1).
| args... | Arguments to perfect forward in the element c-tor |
| Conditional | safety. Strong safety, but the basic one in case: if template type has move c-tor and it throws during moving. All elements in new storage will be destroyed, thus, initial array will start with 'empty' elements and finish with initial ones. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Returns first element in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
Returns first element in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
Returns pointer to the raw underlying array.
|
inlinenoexcept |
Returns pointer to the raw underlying array.
|
inlinenoexcept |
|
inline |
|
inline |
Copy and Move assignment operator.
Implemented through copy/move-and-swap idiom.
| Strong | safety when allocators swap throws. Otherwise noexcept. |
|
inline |
|
inlinenoexcept |
Returns element at n-th index in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
Returns element at n-th index in the array. If index is out of bounds - undefined behaviour.
|
inlinenoexcept |
Destroyes the last object in the array.
The end() iterator is invalidated. If array is empty - undefined behaviour.
| noexcept |
|
inline |
Wrapper for emplaceBack. See docs for emplaceBack.
|
inline |
Preallocates 'new_capacity' memory.
If new_capacity > the actual one - allocates new memory, moves elements into it, deallocates previous storage. All references and iterators are invalidated.
If new capacity <= the actual one, the function has no effect.
| new_capacity | Number of elements to preallocate memory for |
| Conditional | safety. Strong safety, but the basic one in case: if template type has a move c-tor and it throws during moving. All elements in new storage will be destroyed, thus, initial array will start with 'empty' elements and finish with initial ones. |
|
inlinenoexcept |
Returns current number of elements in the Vector.