* Add ranges * Initial Hugo setup * Work in progress * Added selection for local or remote site * Updated to 'light' theme * Changed to using Hextra Hugo theme * Changed to using Hextra Hugo theme * Changed to Hextra Hugo theme * Change to Hextra Hugo theme * Updated Hugo setup. * Updated Hugo setup. # Conflicts: # docs/releases/_index.md * Work in progress * Added new fonts Added new documentation * Latest documentation updates * Latest documentation updates # Conflicts: # docs/containers/array.md # docs/containers/array_view.md # docs/containers/array_wrapper.md # docs/containers/bip_buffer_spsc_atomic.md # docs/containers/bitset.md # docs/containers/indirect_vector.md # docs/containers/vector.md # docs/getting-started/compilers.md * Added bloom_filter markdown doc * Added more documentation Updated CSS for light and dark modes * Fixed some menus Added mode documentation files * Updated CSS rules Added badges to home page Added uniqur_ptr + pool tutorial * Fixed formatting on the home page markdown Modified light amd dark code formatting * Updated unique_ptr-with-pool * Added container and shared message tutorials * Updates to documentation * Added const_multimap * Updated source-formatting.md * Added initial raw text files form Web site editor * Innore coverage build directory * Exported raw text documentation files from the web site editor * Hugo updates * Added Hugo intalation and markdown descriptions * More addition to the documentation * Added closure.md and updates to delegate.md * Added format.md * Added documentation for etl::delegate_observable, etl::function, Base64 codec * Added io_port documentation * Added basic_format_spec * Added documentation for string_stream and string utilities. * Added more documentation Updated the documentation CSS * Added documentation for clocks, day, duration * Added more documentation for chrono classes Updated callouts * More chrono documentation * Completed chrono documentation * Maths functions documentation * Completed maths documentation * Completed maths documentation * Completed maths documentation * Completed maths documentation * Added multiple documentation files * Added iterator.md * Added debug_count.md and versions.md * Added debug_count.md and versions.md * Added more documentation * More documentation * Added some design pattern documentation Modified some of the layout files Modified the About documentation * Converted more documentation pages Modified the site CSS * Added more documentation Moced some documentation files to new directories * Added more documentation Tweaks to CSS * Added callback_timer_deferred_locked documentation * Added callback_timer_locked documentation * More documentation updates * More documentation updates * More documentation updates * New documentation files. Harmonised file name format * New documentation files. * Multiple document updates * Multiple document updates * Final conversion of web pages * Updates before PR * Updates before PR * Updates before PR # Conflicts: # docs/blog/_index.md * Final pre PR updates * Updates to message framework documentation * Renamed directory * Fix spelling * Added author and date to blog files Moved documentation files merged from development * Fixed 'Description' typo * Fix typos # Conflicts: # docs/IO/io_port.md # docs/containers/sets/const-multiset.md # docs/containers/sets/const-set.md # docs/maths/correlation.md # docs/maths/gamma.md * Renamed two files to lower case * Minor renaming * Added author and date * Updated callout on bresenham_line.md Added support for showing the ETL version on the documentation first page, by copying the version.txt file as a hugo asset. Updated the Python 'update_release.py' to copy 'version.txt' * Replace space in filename with hyphen. Added more information to hugo-commands.md * Replace space in filename with hyphen. Added more information to hugo-commands.md # Conflicts: # docs/getting-started/view-the-docs-locally/hugo-commands.md * Added a link to pseudo_moving_average.md * Updated title pages for groups * Fixed missing 404 for non-existent pages * Fixed coordinate variable names in the 'Calculating the intersection' example --------- Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de> Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com> Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.co.uk>
15 KiB
| title | weight |
|---|---|
| indirect_vector | 3 |
{{< callout type="info">}}
Header: indirect_vector.h
Similar to: std::vector
{{< /callout >}}
A fixed capacity vector that uses indirection to access the elements.
Can be more efficient for vectors of large objects, especially when inserting, erasing or sorting.
Supplies function adaptors to allow efficient application of external algorithms.
etl::indirect_vector<typename T, size_t SIZE>
etl::indirect_vector_ext<typename T>
Inherits from etl::iindirect_vector<T>.
etl::iindirect_vector may be used as a size independent pointer or reference type for any etl::indirect_vector instance.
External buffer
etl::indirect_vector_ext<typename T>
With this template, the constructor expects pointer and size parameters to the externally provided indirection lookup vector and pool.
Template deduction guides
C++17 and above
template <typename... T>
etl::indirect_vector(T...)
Example
etl::indirect_vector data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Defines data as an indirect_vector of int, of length 10, containing the supplied data.
Member types
value_type T
size_type std::size_t
difference_type std::ptrdiff_t
reference value_type&
const_reference const value_type&
pointer value_type*
const_pointer const value_type*
indirect_iterator Iterator to the internal lookup vector
indirect_const_iterator Constant iterator to the internal lookup vector
const_pointer const value_type*
iterator Random access iterator
const_iterator Constant random access iterator
reverse_iterator std::reverse_iterator<iterator>
const_reverse_iterator std::reverse_iterator<const_iterator>
Iterators
Both iterator and const_iterator define indirection() member functions that return an indirect_iterator or indirect_const_iterator to the internal lookup vector.
Access to these iterators allows an external algorithm to manipulate the indirect_vector without moving the objects themselves, thereby vastly increasing the efficiency for vectors of large objects.
Function Object Adaptors
Unary and binary function object wrappers are defined to allow algorithms to manipulate the contents of an indirect_vector using a standard function object with indirect iterators.
template <typename TUnaryFunction, typename TReturnType = void>
class unary_function_adaptor
template <typename TBinaryFunction, typename TReturnType = void>
class binary_function_adaptor
Example
Sorting without moving or copying large objects.
// The large data that we are storing in the vector.
struct Data
{
std::array<int, 1000> values;
};
// How to compare Data objects.
bool operator <(const Data& lhs, const Data& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
// The vector of data.
using Vector = etl::indirect_vector<Data, 10>;
Vector v;
// std::less wrapped in a binary_function_adaptor.
using LessThan = typename Vector::binary_function_adaptor<std::less<Data>, bool>;
// Sort the vector without moving or copying actual Data objects.
std::sort(v.begin().indirection(),
v.end().indirection(),
LessThan());
{{< callout type="warning">}}
Warning: This technique is not suitable for algorithms that may leave the container with multiple copies of an object, such as std::remove_if. This is because the algorithm may create multiple copies of the indirect iterator, but only one copy of the object that they point to.
{{< /callout >}}
Constructor
Internal buffer
etl::indirect_vector<typename T, const size_t SIZE>()
etl::indirect_vector<typename T, const size_t SIZE>(size_t initialSize)
etl::indirect_vector<typename T, const size_t SIZE>(size_t initialSize, const T& value)
template <typename TIterator>
etl::indirect_vector<typename T, const size_t SIZE>(TIterator begin, TIterator end)
etl::indirect_vector<typename T, const size_t SIZE>(const etl::indirect_vector<typename T, const size_t SIZE>&)
etl::indirect_vector<typename T, const size_t SIZE>(etl::indirect_vector<typename T, const size_t SIZE>&&)
Description
If the vector is full then emits an etl::vector_full.
If asserts or exceptions are not enabled then undefined behaviour occurs.
External buffer
etl::indirect_vector<typename T, const size_t SIZE>(etl::ivector<T*>& lookup, etl::ipool& storage)
etl::indirect_vector<typename T, const size_t SIZE>(size_t initialSize, etl::ivector<T*>& lookup, etl::ipool& storage)
etl::indirect_vector<typename T, const size_t SIZE>(size_t initialSize, const T& value, etl::ivector<T*>& lookup, etl::ipool& storage)
template <typename TIterator>
etl::indirect_vector<typename T, const size_t SIZE>(TIterator begin, TIterator end, etl::ivector<T*>& lookup, etl::ipool& storage)
etl::indirect_vector<typename T, const size_t SIZE>(const etl::indirect_vector<typename T, const size_t SIZE>&, etl::ivector<T*>& lookup, etl::ipool& storage)
etl::indirect_vector<typename T, const size_t SIZE>(etl::indirect_vector<typename T, const size_t SIZE>&&, etl::ivector<T*>& lookup, etl::ipool& storage)
Description
If the vector is full then emits an etl::vector_full.
If asserts or exceptions are not enabled then undefined behaviour occurs.
Element access
reference at(size_t i)
const_reference at(size_t i) const
Description
Returns a reference or const reference to the indexed element.
Emits an etl::vector_out_of_range if the index is out of range of the array.
If asserts or exceptions are not enabled then undefined behaviour occurs.
reference operator[](size_t i)
const_reference operator[](size_t i) const
Description
Returns a reference or const reference to the indexed element.
if the index is out of range of the array then undefined behaviour occurs.
reference front()
const_reference front() const
Description
Returns a reference or const reference to the first element.
Undefined behaviour if the vector is empty.
reference back()
const_reference back() const
Description
Returns a reference or const reference to the last element.
Undefined behaviour if the vector is empty.
Iterators
iterator begin()
const_iterator begin() const
const_iterator cbegin() const
Description
Returns an iterator to the beginning of the vector.
iterator end()
const_iterator end() const
const_iterator cend() const
Description
Returns an iterator to the end of the vector.
iterator rbegin()
const_reverse_iterator rbegin() const
const_reverse_iterator crbegin() const
Description
Returns a reverse iterator to the beginning of the vector.
iterator rend()
const_reverse_iterator rend() const
const_reverse_iterator crend() const
Description
Returns a reverse iterator to the end of the vector.
Capacity
bool empty() const
Description
Returns true if the size of the vector is zero, otherwise false.
bool full() const
Description
Returns true if the size of the vector is SIZE, otherwise false.
size_t size() const
Description
Returns the size of the vector.
void resize(size_t new_size, T value = T())
Description
Resizes the vector, up to the maximum capacity. Emits an etl::vector_full if the vector does not have the capacity.
size_t max_size() const
Description
Returns the maximum possible size of the vector.
size_t capacity() const
Description
Returns the maximum possible size of the vector.
size_t available() const
Description
Returns the remaining available capacity in the vector.
Modifiers
template <typename TIterator>
void assign(TIterator begin, TIterator end)
void assign(size_t n, const T& value)
Description
Fills the vector with the values. Emits etl::vector_iterator if the distance between begin and end is illegal.
(debug mode only). If asserts or exceptions are not enabled undefined behaviour occurs.
void push_back(const T& value)
void push_back(T&& value)
Description
Pushes a value to the back of the vector.
If the vector is full then emits an etl::vector_full. If asserts or exceptions are not enabled undefined behaviour occurs.
C++03
void emplace()
void emplace(const T1& value1)
void emplace(const T1& value1, const T2& value2)
void emplace(const T1& value1, const T2& value2, const T3& value3)
void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
Description
Constructs an item at the back of the the vector 'in place'.
Supports up to four constructor parameters.
C++11
template <typename… Args>
void emplace(Args&&… args)
Description
Constructs an item at the back of the the vector 'in place'.
Pushes a value to the back of the vector.
If the vector is full then emits an etl::vector_full.
If asserts or exceptions are not enabled undefined behaviour occurs.
C++03
void emplace_back(const T1& value1)
void emplace_back(const T1& value1, const T2& value2)
void emplace_back(const T1& value1, const T2& value2, const T3& value3)
void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
Description
Constructs an item at the back of the the vector 'in place'.
If the vector is full then emits an etl::vector_full. If asserts or exceptions are not enabled undefined behaviour occurs.
Supports up to four constructor parameters.
Before: 20.35.10
reference emplace_back() 20.38.0
reference emplace_back(const T1& value1)
reference emplace_back(const T1& value1, const T2& value2)
reference emplace_back(const T1& value1, const T2& value2, const T3& value3)
reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
Description
Constructs an item at the back of the the vector 'in place'.
If the vector is full then emits an etl::vector_full. If asserts or exceptions are not enabled undefined behaviour occurs.
Supports up to four constructor parameters.
Since: 20.35.10
C++11
template <typename Args...>
void emplace_back(Args&&... args)
Description
Constructs an item at the back of the the vector 'in place'.
If the vector is full then emits an etl::vector_full. If asserts or exceptions are not enabled undefined behaviour occurs.
Before: 20.35.10
template <typename Args...>
reference emplace_back(Args&&... args)
Description
Constructs an item at the back of the the vector 'in place'.
Supports up to four constructor parameters.
If the vector is full then emits an etl::vector_full. If asserts or exceptions are not enabled undefined behaviour occurs.
Since: 20.35.10
void pop_back()
Description
Pop a value from the back of the vector.
If the vector is empty and ETL_CHECK_PUSH_POP is defined then emits an etl::vector_empty.
If asserts or exceptions are not enabled undefined behaviour occurs.
template <typename TIterator>
void insert(iterator position, TIterator begin, TIterator end)
Description
Insert the range [begin, end) at position.
Before: 20.19.0
template <typename TIterator>
iterator insert(const_iterator position, TIterator begin, TIterator end)
Description
Insert the range [begin, end) at position.
Since: 20.20.0
Return
position
iterator insert(iterator position, const T& value)
iterator insert(iterator position, T&& value)
Description
Insert value at position.
Return
position
iterator insert(const_iterator position, const T& value)
iterator insert(const_iterator position, T&& value)
Description
Insert value at position.
Return
position
void insert(iterator position, size_t n, const T& value)
Description
Inserts n copies of value at position.
iterator insert(const_iterator position, size_t n, const T& value)
Description
Inserts values in to the vector.
If the vector is full then emits an etl::vector_full exception. If asserts or exceptions are not enabled undefined behaviour occurs.
template <typename TIterator>
iterator erase(TIterator begin, TIterator end)
Description
Erase elements in the range [begin, end).
Return
An iterator to the element after the erased range.
<=20.19.0
iterator erase(iterator position)
Description
Erases values in the vector.
Iterators are not checked.
Before: 20.20.0
iterator erase(iterator position)
iterator erase(const_iterator position)
Description
Erases values in the vector.
Iterators are not checked.
Since: 20.20.0
Return
An iterator to the element after the erased element.
void clear()
Description
Clears the vector to a size of zero.
void sort()
Description
Sorts the elements using the 'less than' operator.
template <typename TCompare>
void sort(TCompare compare)
Description
Sorts the elements using the supplied compare.
void sort(iterator first, iterator last)
Description
Sorts a range of elements using the supplied 'less than' operator.
template <typename TCompare>
void sort(iterator first, iterator last, TCompare compare)
Description
Sorts a range of elements using the supplied compare.
void stable_sort()
Description
Stable sorts the elements using the 'less than' operator.
template <typename TCompare>
void stable_sort(TCompare compare)
Description
Stable sorts the elements using the supplied compare.
void stable_sort(iterator first, iterator last)
Description
Stable sorts a range of elements using the supplied 'less than' operator.
template <typename TCompare>
void stable_sort(iterator first, iterator last, TCompare compare)
Description
Stable sorts a range of elements using the supplied compare.
Non-member functions
operator ==
Description
true if the contents of the vectors are equal, otherwise false.
operator !=
Description
true if the contents of the vectors are not equal, otherwise false.
operator <
Description
true if the contents of the lhs are lexicographically less than the contents of the rhs, otherwise false.
operator <=
Description
true if the contents of the lhs are lexicographically less than or equal to the contents of the rhs, otherwise false.
operator >
Description
true if the contents of the lhs are lexicographically greater than the contents of the rhs, otherwise false.
operator >=
Description
true if the contents of the lhs are lexicographically greater than or equal to the contents of the rhs, otherwise false.