Resource limited wrapper of std::vector. More...
#include <ResourceLimitedVector.hpp>
Public Types | |
using | configuration_type = _LimitsConfig |
using | collection_type = _Collection |
using | value_type = _Ty |
using | allocator_type = _Alloc |
using | pointer = typename collection_type::pointer |
using | const_pointer = typename collection_type::const_pointer |
using | reference = typename collection_type::reference |
using | const_reference = typename collection_type::const_reference |
using | size_type = typename collection_type::size_type |
using | difference_type = typename collection_type::difference_type |
using | iterator = typename collection_type::iterator |
using | const_iterator = typename collection_type::const_iterator |
using | reverse_iterator = typename collection_type::reverse_iterator |
using | const_reverse_iterator = typename collection_type::const_reverse_iterator |
Public Member Functions | |
ResourceLimitedVector (configuration_type cfg=configuration_type(), const allocator_type &alloc=allocator_type()) | |
Construct a ResourceLimitedVector. More... | |
ResourceLimitedVector (const ResourceLimitedVector &other) | |
virtual | ~ResourceLimitedVector ()=default |
ResourceLimitedVector & | operator= (const ResourceLimitedVector &other) |
iterator | insert (const_iterator pos, const value_type &value) |
Insert value before pos. More... | |
iterator | insert (const_iterator pos, value_type &&value) |
Insert value before pos. More... | |
pointer | push_back (const value_type &val) |
Add element at the end. More... | |
pointer | push_back (value_type &&val) |
Add element at the end. More... | |
template<typename ... Args> | |
pointer | emplace_back (Args &&... args) |
Construct and insert element at the end. More... | |
bool | remove (const value_type &val) |
Remove element. More... | |
template<class UnaryPredicate > | |
bool | remove_if (UnaryPredicate pred) |
Remove element. More... | |
template<class InputIterator > | |
void | assign (InputIterator first, InputIterator last) |
Assign vector content. More... | |
void | assign (size_type n, const value_type &val) |
Assign vector content. More... | |
void | assign (std::initializer_list< value_type > il) |
Assign vector content. More... | |
operator const collection_type & () const noexcept | |
Const cast to underlying collection. More... | |
reference | at (size_type pos) |
Wrappers to other basic vector methods. More... | |
const_reference | at (size_type pos) const |
reference | operator[] (size_type pos) |
const_reference | operator[] (size_type pos) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
iterator | begin () noexcept |
const_iterator | begin () const noexcept |
const_iterator | cbegin () const noexcept |
iterator | end () noexcept |
const_iterator | end () const noexcept |
const_iterator | cend () const noexcept |
reverse_iterator | rbegin () noexcept |
const_reverse_iterator | rbegin () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
reverse_iterator | rend () noexcept |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crend () const noexcept |
bool | empty () const noexcept |
size_type | size () const noexcept |
size_type | capacity () const noexcept |
size_type | max_size () const noexcept |
void | clear () |
iterator | erase (const_iterator pos) |
iterator | erase (const_iterator first, const_iterator last) |
void | pop_back () |
value_type * | data () |
const value_type * | data () const |
Protected Member Functions | |
bool | ensure_capacity () |
Make room for one item. More... | |
template<typename Enabler = _KeepOrderEnabler> | |
std::enable_if<!Enabler::value, void >::type | do_remove (iterator it) |
Remove element. More... | |
template<typename Enabler = _KeepOrderEnabler> | |
std::enable_if< Enabler::value, void >::type | do_remove (iterator it) |
Remove element. More... | |
Protected Attributes | |
configuration_type | configuration_ |
collection_type | collection_ |
Resource limited wrapper of std::vector.
This template class holds an unordered collection of elements using a std::vector or a replacement. It makes use of a ResourceLimitedContainerConfig to setup the allocation behaviour regarding the number of elements in the collection.
It features linear increment of the capacity, initial preallocation, and maximum number of elements control.
_Ty | Element type. |
_KeepOrderEnabler | Indicates if element order should be kept when removing items, defaults to std::false_type. |
_LimitsConfig | Type defining the resource limits configuration, defaults to ResourceLimitedContainerConfig |
_Alloc | Allocator to use on the underlying collection type, defaults to std::allocator<_Ty>. |
_Collection | Type used to store the collection of items, defaults to std::vector<_Ty, _Alloc>. |
using allocator_type = _Alloc |
using collection_type = _Collection |
using configuration_type = _LimitsConfig |
using const_iterator = typename collection_type::const_iterator |
using const_pointer = typename collection_type::const_pointer |
using const_reference = typename collection_type::const_reference |
using const_reverse_iterator = typename collection_type::const_reverse_iterator |
using difference_type = typename collection_type::difference_type |
using iterator = typename collection_type::iterator |
using pointer = typename collection_type::pointer |
using reference = typename collection_type::reference |
using reverse_iterator = typename collection_type::reverse_iterator |
using size_type = typename collection_type::size_type |
using value_type = _Ty |
|
inline |
Construct a ResourceLimitedVector.
This constructor receives a ResourceLimitedContainerConfig to setup the allocation behaviour regarding the number of elements in the collection.
The cfg parameter indicates the initial number to be reserved, the maximum number of items allowed, and the capacity increment value.
cfg | Resource limits configuration to use. |
alloc | Allocator object. Forwarded to collection constructor. |
|
inline |
|
virtualdefault |
|
inline |
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
first,last | Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last. The function template argument InputIterator shall be an input iterator type that points to elements of a type from which value_type objects can be constructed. If the size of this range is greater than the maximum number of elements allowed on the resource limits configuration, the elements exceeding that maximum will be silently discarded. |
|
inline |
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
n | New size for the container. Will be truncated if greater than the maximum allowed on the resource limits configuration. |
val | Value to fill the container with. Each of the n elements in the container will be initialized to a copy of this value. |
|
inline |
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
il | An initializer_list object. The compiler will automatically construct such objects from initializer list declarators. Member type value_type is the type of the elements in the container. If the size of this list is greater than the maximum number of elements allowed on the resource limits configuration, the elements exceeding that maximum will be silently discarded. |
Wrappers to other basic vector methods.
Please refer to https://en.cppreference.com/w/cpp/container/vector
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlineprotected |
Remove element.
Removes the element pointed to by it. All iterators may become invalidated if this method returns true. This version doesn't keep the order of insertion, optimizing the number of copies performed.
it | Iterator pointing to the item to be removed. |
|
inlineprotected |
Remove element.
Removes the element pointed to by it. All iterators may become invalidated if this method returns true. This version keeps the order of insertion, so when removing an item different from the last one, part of the collection will be copied.
it | Iterator pointing to the item to be removed. |
|
inline |
Construct and insert element at the end.
Inserts a new element at the end of the vector, right after its current last element. This new element is constructed in place using args as the arguments for its constructor.
args | Arguments forwarded to construct the new element. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineprotected |
Make room for one item.
Tries to ensure that a new item can be added to the container.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
Const cast to underlying collection.
Useful to easy integration on old APIs where a traditional container was used.
|
inline |
|
inline |
|
inline |
|
inline |
Add element at the end.
Adds a new element at the end of the vector, after its current last element. The content of val is copied to the new element.
val | Value to be copied to the new element. |
|
inline |
Add element at the end.
Adds a new element at the end of the vector, after its current last element. The content of val is moved to the new element.
val | Value to be moved to the new element. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Remove element.
Removes the first element in the vector that compares equal to val. All iterators may become invalidated if this method returns true.
val | Value to be compared. |
|
inline |
Remove element.
Removes the first element in the vector for which pred returns true. All iterators may become invalidated if this method returns true.
pred | Unary function that accepts an element in the range as argument and returns a value convertible to bool. The value returned indicates whether the element is considered a match in the context of this function. The function shall not modify its argument. This can either be a function pointer or a function object. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
protected |
|
protected |