template<typename _Ty, typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
class eprosima::fastrtps::ResourceLimitedVector< _Ty, _KeepOrderEnabler, _LimitsConfig, _Alloc, _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.
- Template Parameters
-
_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>. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
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.
- Parameters
-
cfg | Resource limits configuration to use. |
alloc | Allocator object. Forwarded to collection constructor. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
template<class InputIterator >
void assign |
( |
InputIterator |
first, |
|
|
InputIterator |
last |
|
) |
| |
|
inline |
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
- Parameters
-
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. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
- Parameters
-
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. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
void assign |
( |
std::initializer_list< value_type > |
il | ) |
|
|
inline |
Assign vector content.
Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.
- Parameters
-
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. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
Contains element.
Checks whether the given element is present in the collection (at least once).
- Parameters
-
- Returns
- true if the element is present in the collection (at least once), false otherwise.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
template<typename Enabler = _KeepOrderEnabler>
std::enable_if<!Enabler::value, void >::type do_remove |
( |
iterator |
it | ) |
|
|
inlineprotected |
Remove element.
Removes the element pointed to by it. All iterators may become invalidated. This version doesn't keep the order of insertion, optimizing the number of copies performed.
- Parameters
-
it | Iterator pointing to the item to be removed. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
template<typename Enabler = _KeepOrderEnabler>
std::enable_if< Enabler::value, void >::type do_remove |
( |
iterator |
it | ) |
|
|
inlineprotected |
Remove element.
Removes the element pointed to by it. All iterators may become invalidated. This version keeps the order of insertion, so when removing an item different from the last one, part of the collection will be copied.
- Parameters
-
it | Iterator pointing to the item to be removed. |
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
template<typename ... Args>
pointer emplace_back |
( |
Args &&... |
args | ) |
|
|
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.
- Parameters
-
args | Arguments forwarded to construct the new element. |
- Returns
- pointer to the new element, nullptr if resource limit is reached.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
Make room for one item.
Tries to ensure that a new item can be added to the container.
- Returns
- true if there is room for a new item, false if resource limit is reached.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
Const cast to underlying collection.
Useful to easy integration on old APIs where a traditional container was used.
- Returns
- const reference to the underlying collection.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
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.
- Parameters
-
val | Value to be copied to the new element. |
- Returns
- pointer to the new element, nullptr if resource limit is reached.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
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.
- Parameters
-
val | Value to be moved to the new element. |
- Returns
- pointer to the new element, nullptr if resource limit is reached.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
Remove element.
Removes the first element in the vector that compares equal to val. All iterators may become invalidated if this method returns true.
- Parameters
-
- Returns
- true if an element was removed, false otherwise.
template<typename _Ty , typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
template<class UnaryPredicate >
bool remove_if |
( |
UnaryPredicate |
pred | ) |
|
|
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.
- Parameters
-
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. |
- Returns
- true if an element was removed, false otherwise.