3#include <tcb_span/span.hpp>
17template <
typename T,
size_t capacity>
19 std::array<T, capacity> data_{};
31 template <
typename Collection>
32 StaticVector(Collection
const& collection) : size_(std::min(collection.size(), capacity)) {
33 assert(collection.size() <= capacity &&
34 "rsl::StaticVector::StaticVector: Input exceeds capacity");
35 std::copy(collection.cbegin(),
36 collection.cbegin() +
typename Collection::difference_type(size_), data_.begin());
48 [[nodiscard]]
auto begin() {
return data_.begin(); }
53 [[nodiscard]]
auto begin()
const {
return data_.cbegin(); }
58 [[nodiscard]]
auto end() {
return data_.begin() + size_; }
63 [[nodiscard]]
auto end()
const {
return data_.cbegin() + size_; }
68 operator tcb::span<T>() {
return tcb::span<T>(data_.data(), size_); }
73 operator tcb::span<T const>()
const {
return tcb::span<T const>(data_.data(), size_); }
79template <
typename T,
size_t capacity>
81 return std::vector<T>(static_vector.
begin(), static_vector.
end());
Fixed capacity vector with an implicit conversion to tcb::span. Capacity is specified as a template p...
Definition static_vector.hpp:18
auto begin() const
Get a const begin iterator.
Definition static_vector.hpp:53
StaticVector()=default
Construct an empty vector.
StaticVector(Collection const &collection)
Construct from another container.
Definition static_vector.hpp:32
auto begin()
Get a mutable begin iterator.
Definition static_vector.hpp:48
auto end() const
Get a const end iterator.
Definition static_vector.hpp:63
auto end()
Get a mutable end iterator.
Definition static_vector.hpp:58
StaticVector(std::initializer_list< T > const &collection)
Construct from a std::initializer_list.
Definition static_vector.hpp:42
auto to_vector(StaticVector< T, capacity > const &static_vector)
Explicit conversion to std::vector<T>
Definition static_vector.hpp:80