tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
static_vector< T, Capacity > Struct Template Reference

Dynamically-resizable fixed-capacity vector. More...

#include <etl/vector.hpp>

Inheritance diagram for static_vector< T, Capacity >:

Public Types

using const_iterator = typename base_type::const_pointer
 The type being used.
 
using const_pointer = typename base_type::const_pointer
 The type being used.
 
using const_reference = value_type const &
 The type being used.
 
using const_reverse_iterator = etl::reverse_iterator< const_iterator >
 The type being used.
 
using difference_type = ptrdiff_t
 The type being used.
 
using iterator = typename base_type::pointer
 The type being used.
 
using pointer = typename base_type::pointer
 The type being used.
 
using reference = value_type &
 The type being used.
 
using reverse_iterator = etl::reverse_iterator< iterator >
 The type being used.
 
using size_type = size_t
 The type being used.
 
using value_type = typename base_type::value_type
 The type being used.
 

Public Member Functions

constexpr static_vector ()=default
 
template<etl::size_t Size>
requires (Size <= Capacity)
constexpr static_vector (c_array< T, Size > &&source)
 
template<typename InputIter >
requires (detail::InputIterator<InputIter>)
constexpr static_vector (InputIter first, InputIter last)
 Initialize vector from range [first, last).
 
constexpr static_vector (size_type n) noexcept(noexcept(emplace_n(n)))
 Initializes vector with n default-constructed elements.
 
constexpr static_vector (size_type n, T const &value) noexcept(noexcept(insert(begin(), n, value)))
 Initializes vector with n with value.
 
template<etl::same_as< empty_c_array > Source = empty_c_array>
constexpr static_vector (Source) noexcept
 
constexpr static_vector (static_vector &&other) noexcept(noexcept(move_insert(begin(), other.begin(), other.end())))
 Move constructor.
 
constexpr static_vector (static_vector const &other) noexcept(noexcept(insert(begin(), other.begin(), other.end())))
 Copy constructor.
 
template<typename InputIter >
requires (detail::InputIterator<InputIter>)
constexpr auto assign (InputIter first, InputIter last) noexcept(noexcept(clear()) and noexcept(insert(begin(), first, last))) -> void
 assign
 
constexpr auto assign (size_type n, T const &u) -> void requires(is_copy_constructible_v< T >)
 
constexpr auto back () const noexcept -> const_reference
 
constexpr auto back () noexcept -> reference
 back
 
constexpr auto begin () const noexcept -> const_iterator
 
constexpr auto begin () noexcept -> iterator
 
constexpr auto capacity () const noexcept -> size_type
 Maximum number of elements that can be allocated in the vector.
 
constexpr auto cbegin () const noexcept -> const_iterator
 
constexpr auto cbegin () noexcept -> const_iterator
 
constexpr auto cend () const noexcept -> const_iterator
 
constexpr auto cend () noexcept -> const_iterator
 
constexpr void clear () noexcept
 Clears the vector.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 
template<typename... Args>
requires (is_constructible_v<T, Args...>)
constexpr auto emplace (const_iterator position, Args &&... args) noexcept(noexcept(move_insert(position, declval< value_type * >(), declval< value_type * >()))) -> iterator
 
constexpr auto end () const noexcept -> const_iterator
 
constexpr auto end () noexcept -> iterator
 
constexpr auto erase (const_iterator first, const_iterator last) noexcept -> iterator requires(detail::is_movable_v< value_type >)
 
constexpr auto erase (const_iterator position) noexcept -> iterator requires(detail::is_movable_v< value_type >)
 erase
 
constexpr auto front () const noexcept -> const_reference
 
constexpr auto front () noexcept -> reference
 front
 
constexpr auto insert (const_iterator position, const_reference x) noexcept(noexcept(insert(position, size_type(1), x))) -> iterator requires(is_copy_constructible_v< T >)
 
template<typename InputIt >
constexpr auto insert (const_iterator position, InputIt first, InputIt last) noexcept(noexcept(emplace_back(*first))) -> iterator requires(detail::InputIterator< InputIt > &&is_constructible_v< value_type, detail::iterator_reference_t< InputIt > >)
 
constexpr auto insert (const_iterator position, size_type n, T const &x) noexcept(noexcept(push_back(x))) -> iterator requires(is_copy_constructible_v< T >)
 
constexpr auto insert (const_iterator position, value_type &&x) noexcept(noexcept(move_insert(position, &x, &x+1))) -> iterator requires(is_move_constructible_v< T >)
 
constexpr auto max_size () const noexcept -> size_type
 
template<typename InIt >
requires (detail::InputIterator<InIt>)
constexpr auto move_insert (const_iterator position, InIt first, InIt last) noexcept(noexcept(emplace_back(etl::move(*first)))) -> iterator
 
constexpr auto operator= (static_vector &&other) noexcept(noexcept(clear()) and noexcept(move_insert(begin(), other.begin(), other.end()))) -> static_vector &requires(is_assignable_v< reference, reference >)
 Move assignment.
 
constexpr auto operator= (static_vector const &other) noexcept(noexcept(clear()) &&noexcept(insert(begin(), other.begin(), other.end()))) -> static_vector &requires(is_assignable_v< reference, const_reference >)
 Copy assignment.
 
constexpr auto operator[] (size_type pos) const noexcept -> const_reference
 Unchecked access to element at index pos (UB if index not in.
 
constexpr auto operator[] (size_type pos) noexcept -> reference
 Unchecked access to element at index pos (UB if index not in.
 
template<typename U >
requires (is_constructible_v<T, U> and is_assignable_v<reference, U &&>)
constexpr auto push_back (U &&value) noexcept(noexcept(emplace_back(etl::forward< U >(value)))) -> void
 Appends value at the end of the vector.
 
constexpr auto rbegin () const noexcept -> const_reverse_iterator
 
constexpr auto rbegin () noexcept -> reverse_iterator
 
constexpr auto rend () const noexcept -> const_reverse_iterator
 
constexpr auto rend () noexcept -> reverse_iterator
 
constexpr auto resize (size_type sz) noexcept((is_move_constructible_v< T > &&is_nothrow_move_constructible_v< T >)||(is_copy_constructible_v< T > &&is_nothrow_copy_constructible_v< T >)) -> void requires(detail::is_movable_v< value_type >)
 Resizes the container to contain sz elements. If elements need to be appended, these are move-constructed from T{} (or copy-constructed.
 
constexpr auto resize (size_type sz, T const &value) noexcept(is_nothrow_copy_constructible_v< T >) -> void requires(is_copy_constructible_v< T >)
 
constexpr auto size () const noexcept -> size_type
 Number of elements in the vector.
 
constexpr auto swap (static_vector &other) noexcept(is_nothrow_swappable_v< T >) -> void requires(is_assignable_v< T &, T && >)
 Exchanges the contents of the container with those of other.
 

Detailed Description

template<typename T, size_t Capacity>
struct etl::static_vector< T, Capacity >

Dynamically-resizable fixed-capacity vector.

// SPDX-License-Identifier: BSL-1.0
// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
#include <etl/cassert.hpp>
#if defined(TETL_ENABLE_CXX_MODULES)
import etl;
#else
#include <etl/vector.hpp>
#endif
struct Person {
constexpr Person(int a, int e) noexcept
: age{a}
{
}
friend constexpr auto operator==(Person lhs, Person rhs) noexcept -> bool = default;
int age{};
int experience{};
};
auto main() -> int
{
// Unlike a std::vector you will have to decide which maximum capacity you
// need. Apart from that it behaves almost the same as the standard version.
assert(people.empty());
assert(people.capacity() == 32);
// You can push_back/emplace_back into the vector
people.push_back(Person{20, 0});
assert(people.size() == 1);
assert(people.back().age == 20);
people.emplace_back(90, 100);
assert(people.size() == 2);
assert(people.back().age == 90);
// You can make copies.
auto const copy = people;
// You can compare vectors
assert(copy == people);
// You can apply algorithms.
auto levelUp = [](auto p) {
p.experience += 1;
return p;
};
etl::transform(begin(people), end(people), begin(people), levelUp);
assert(people[0].experience == 1);
assert(people[1].experience == 101);
assert(copy != people);
return 0;
}
#define assert(...)
Definition cassert.hpp:20
constexpr auto transform(InputIt first, InputIt last, OutputIt dest, UnaryOp op) -> OutputIt
Definition transform.hpp:25
constexpr auto copy(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Copies the elements in the range, defined by [first, last), to another range beginning at destination...
Definition copy.hpp:19
constexpr auto operator==(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Checks if lhs and rhs are equal, i.e. the number of ticks for the type common...
Definition duration.hpp:309
The class template bitset represents a fixed-size sequence of Bits bits. Bitsets can be manipulated b...
Definition bitset.hpp:23
constexpr auto begin() noexcept -> iterator
Definition static_vector.hpp:448
constexpr auto end() noexcept -> iterator
Definition static_vector.hpp:458
Examples
algorithm.cpp.

Member Typedef Documentation

◆ const_iterator

template<typename T , size_t Capacity>
using const_iterator = typename base_type::const_pointer

The type being used.

◆ const_pointer

template<typename T , size_t Capacity>
using const_pointer = typename base_type::const_pointer

The type being used.

◆ const_reference

The type being used.

◆ const_reverse_iterator

The type being used.

◆ difference_type

template<typename T , size_t Capacity>
using difference_type = ptrdiff_t

The type being used.

◆ iterator

template<typename T , size_t Capacity>
using iterator = typename base_type::pointer

The type being used.

◆ pointer

template<typename T , size_t Capacity>
using pointer = typename base_type::pointer

The type being used.

◆ reference

template<typename T , size_t Capacity>
using reference = value_type&

The type being used.

◆ reverse_iterator

The type being used.

◆ size_type

template<typename T , size_t Capacity>
using size_type = size_t

The type being used.

◆ value_type

template<typename T , size_t Capacity>
using value_type = typename base_type::value_type

The type being used.

Constructor & Destructor Documentation

◆ static_vector() [1/8]

template<typename T , size_t Capacity>
constexpr static_vector ( )
constexprdefault

◆ static_vector() [2/8]

template<typename T , size_t Capacity>
template<etl::same_as< empty_c_array > Source = empty_c_array>
constexpr static_vector ( Source  )
inlineconstexprnoexcept

◆ static_vector() [3/8]

template<typename T , size_t Capacity>
template<etl::size_t Size>
requires (Size <= Capacity)
constexpr static_vector ( c_array< T, Size > &&  source)
inlineconstexpr

◆ static_vector() [4/8]

template<typename T , size_t Capacity>
constexpr static_vector ( static_vector< T, Capacity > const other)
inlineconstexprnoexcept

Copy constructor.

◆ static_vector() [5/8]

template<typename T , size_t Capacity>
constexpr static_vector ( static_vector< T, Capacity > &&  other)
inlineconstexprnoexcept

Move constructor.

◆ static_vector() [6/8]

template<typename T , size_t Capacity>
constexpr static_vector ( size_type  n)
inlineexplicitconstexprnoexcept

Initializes vector with n default-constructed elements.

◆ static_vector() [7/8]

template<typename T , size_t Capacity>
constexpr static_vector ( size_type  n,
T const value 
)
inlineconstexprnoexcept

Initializes vector with n with value.

◆ static_vector() [8/8]

template<typename T , size_t Capacity>
template<typename InputIter >
requires (detail::InputIterator<InputIter>)
constexpr static_vector ( InputIter  first,
InputIter  last 
)
inlineconstexpr

Initialize vector from range [first, last).

Member Function Documentation

◆ assign() [1/2]

template<typename T , size_t Capacity>
template<typename InputIter >
requires (detail::InputIterator<InputIter>)
constexpr auto assign ( InputIter  first,
InputIter  last 
) -> void
inlineconstexprnoexcept

assign

◆ assign() [2/2]

template<typename T , size_t Capacity>
constexpr auto assign ( size_type  n,
T const u 
) -> void requires(is_copy_constructible_v<T>)
inlineconstexpr

◆ back() [1/2]

template<typename T , size_t Capacity>
constexpr auto back ( ) const -> const_reference
inlineconstexprnoexcept

◆ back() [2/2]

template<typename T , size_t Capacity>
constexpr auto back ( ) -> reference
inlineconstexprnoexcept

back

◆ begin() [1/2]

template<typename T , size_t Capacity>
constexpr auto begin ( ) const -> const_iterator
inlineconstexprnoexcept

◆ begin() [2/2]

template<typename T , size_t Capacity>
constexpr auto begin ( ) -> iterator
inlineconstexprnoexcept

◆ capacity()

template<typename T , size_t Capacity>
constexpr auto capacity ( ) const -> size_type
inlineconstexprnoexcept

Maximum number of elements that can be allocated in the vector.

◆ cbegin() [1/2]

template<typename T , size_t Capacity>
constexpr auto cbegin ( ) const -> const_iterator
inlineconstexprnoexcept

◆ cbegin() [2/2]

template<typename T , size_t Capacity>
constexpr auto cbegin ( ) -> const_iterator
inlineconstexprnoexcept

◆ cend() [1/2]

template<typename T , size_t Capacity>
constexpr auto cend ( ) const -> const_iterator
inlineconstexprnoexcept

◆ cend() [2/2]

template<typename T , size_t Capacity>
constexpr auto cend ( ) -> const_iterator
inlineconstexprnoexcept

◆ clear()

template<typename T , size_t Capacity>
constexpr void clear ( )
inlineconstexprnoexcept

Clears the vector.

◆ crbegin()

template<typename T , size_t Capacity>
constexpr auto crbegin ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

◆ crend()

template<typename T , size_t Capacity>
constexpr auto crend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

◆ emplace()

template<typename T , size_t Capacity>
template<typename... Args>
requires (is_constructible_v<T, Args...>)
constexpr auto emplace ( const_iterator  position,
Args &&...  args 
) -> iterator
inlineconstexprnoexcept

◆ end() [1/2]

template<typename T , size_t Capacity>
constexpr auto end ( ) const -> const_iterator
inlineconstexprnoexcept

◆ end() [2/2]

template<typename T , size_t Capacity>
constexpr auto end ( ) -> iterator
inlineconstexprnoexcept

◆ erase() [1/2]

template<typename T , size_t Capacity>
constexpr auto erase ( const_iterator  first,
const_iterator  last 
) -> iterator requires(detail::is_movable_v<value_type>)
inlineconstexprnoexcept

◆ erase() [2/2]

template<typename T , size_t Capacity>
constexpr auto erase ( const_iterator  position) -> iterator requires(detail::is_movable_v<value_type>)
inlineconstexprnoexcept

erase

◆ front() [1/2]

template<typename T , size_t Capacity>
constexpr auto front ( ) const -> const_reference
inlineconstexprnoexcept

◆ front() [2/2]

template<typename T , size_t Capacity>
constexpr auto front ( ) -> reference
inlineconstexprnoexcept

front

◆ insert() [1/4]

template<typename T , size_t Capacity>
constexpr auto insert ( const_iterator  position,
const_reference  x 
) -> iterator requires(is_copy_constructible_v<T>)
inlineconstexprnoexcept

◆ insert() [2/4]

template<typename T , size_t Capacity>
template<typename InputIt >
constexpr auto insert ( const_iterator  position,
InputIt  first,
InputIt  last 
) -> iterator requires( detail::InputIterator<InputIt> && is_constructible_v<value_type, detail::iterator_reference_t<InputIt>> )
inlineconstexprnoexcept

◆ insert() [3/4]

template<typename T , size_t Capacity>
constexpr auto insert ( const_iterator  position,
size_type  n,
T const x 
) -> iterator requires(is_copy_constructible_v<T>)
inlineconstexprnoexcept

◆ insert() [4/4]

template<typename T , size_t Capacity>
constexpr auto insert ( const_iterator  position,
value_type &&  x 
) -> iterator requires(is_move_constructible_v<T>)
inlineconstexprnoexcept

◆ max_size()

template<typename T , size_t Capacity>
constexpr auto max_size ( ) const -> size_type
inlineconstexprnoexcept

◆ move_insert()

template<typename T , size_t Capacity>
template<typename InIt >
requires (detail::InputIterator<InIt>)
constexpr auto move_insert ( const_iterator  position,
InIt  first,
InIt  last 
) -> iterator
inlineconstexprnoexcept

◆ operator=() [1/2]

template<typename T , size_t Capacity>
constexpr auto operator= ( static_vector< T, Capacity > &&  other) -> static_vector& requires(is_assignable_v<reference, reference>)
inlineconstexprnoexcept

Move assignment.

◆ operator=() [2/2]

template<typename T , size_t Capacity>
constexpr auto operator= ( static_vector< T, Capacity > const other) -> static_vector& requires(is_assignable_v<reference, const_reference>)
inlineconstexprnoexcept

Copy assignment.

◆ operator[]() [1/2]

template<typename T , size_t Capacity>
constexpr auto operator[] ( size_type  pos) const -> const_reference
inlineconstexprnoexcept

Unchecked access to element at index pos (UB if index not in.

◆ operator[]() [2/2]

template<typename T , size_t Capacity>
constexpr auto operator[] ( size_type  pos) -> reference
inlineconstexprnoexcept

Unchecked access to element at index pos (UB if index not in.

◆ push_back()

template<typename T , size_t Capacity>
template<typename U >
requires (is_constructible_v<T, U> and is_assignable_v<reference, U &&>)
constexpr auto push_back ( U &&  value) -> void
inlineconstexprnoexcept

Appends value at the end of the vector.

Examples
algorithm.cpp.

◆ rbegin() [1/2]

template<typename T , size_t Capacity>
constexpr auto rbegin ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

◆ rbegin() [2/2]

template<typename T , size_t Capacity>
constexpr auto rbegin ( ) -> reverse_iterator
inlineconstexprnoexcept

◆ rend() [1/2]

template<typename T , size_t Capacity>
constexpr auto rend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

◆ rend() [2/2]

template<typename T , size_t Capacity>
constexpr auto rend ( ) -> reverse_iterator
inlineconstexprnoexcept

◆ resize() [1/2]

template<typename T , size_t Capacity>
constexpr auto resize ( size_type  sz) -> void requires(detail::is_movable_v<value_type>)
inlineconstexprnoexcept

Resizes the container to contain sz elements. If elements need to be appended, these are move-constructed from T{} (or copy-constructed.

◆ resize() [2/2]

template<typename T , size_t Capacity>
constexpr auto resize ( size_type  sz,
T const value 
) -> void requires(is_copy_constructible_v<T>)
inlineconstexprnoexcept

◆ size()

template<typename T , size_t Capacity>
constexpr auto size ( ) const -> size_type
inlineconstexprnoexcept

Number of elements in the vector.

◆ swap()

template<typename T , size_t Capacity>
constexpr auto swap ( static_vector< T, Capacity > &  other) -> void requires(is_assignable_v<T&, T &&>)
inlineconstexprnoexcept

Exchanges the contents of the container with those of other.


The documentation for this struct was generated from the following file: