class Vec
Declaration
template <class T>
class Vec { /* full declaration omitted */ };
Description
A resizeable contiguous buffer of type `T`. Vec requires Move for its items: - They can't be references as a pointer to reference is not valid. - On realloc, items need to be moved between allocations. Vec requires items are not references: - References can not be moved in the vector as assignment modifies the pointee, and Vec does not wrap references to store them as pointers (for now). Vec requires items are not const: - A const Vec <T > contains const values, it does not give mutable access to its contents, so the const internal type would be redundant.
Declared at: sus/collections/vec.h:84
Templates
- T
Member Variables
- public std::allocator<T> allocator_
- public sus::num::usize capacity_
- public ::sus::iter::IterRefCounter iter_refs_
- public T* data_
- public sus::num::usize len_
- public static const sus::num::usize kMovedFromLen = 1_usize
- The length is set to this value when `Vec` is moved from. It is non-zero as `is_moved_from()` returns true when `length > capacity`.
- public static const sus::num::usize kMovedFromCapacity = 0_usize
- The capacity is set to this value when `Vec` is moved from. It is zero to signal that the Vec is unallocated, and it is less than kMovedFromLen to signal its moved-from state.
- public static const bool SusUnsafeTrivialRelocate = ::sus::mem::TriviallyRelocatable<decltype(allocator_), sus::iter::IterRefCounter, sus::num::usize, decltype(data_), sus::num::usize>
Method Overview
- public template <class... Ts>constexpr Vec<T>(Ts &&... values) noexcept
- public constexpr Vec<T>(::sus::marker::EmptyMarker)
- public constexpr Vec<T>(sus::collections::Vec::WithCapacity, std::allocator<T> alloc, sus::num::usize cap)
- public constexpr Vec<T>(sus::collections::Vec::FromParts, std::allocator<T> alloc, sus::num::usize cap, T * ptr, sus::num::usize len)
- public constexpr T * alloc_internal_check_cap(sus::num::usize cap) noexcept
- public constexpr sus::num::usize apply_growth_function(sus::num::usize additional) const noexcept
- public constexpr SliceMut<T> as_mut_slice() & noexcept
- public constexpr void destroy_storage_objects()
- public constexpr void free_storage()
- public static constexpr Vec<T> from(::sus::SliceMut<T> slice) noexcept
- public static constexpr Vec<T> from(::sus::Slice<T> slice) noexcept
- public static constexpr Vec<T> from_raw_parts(::sus::marker::UnsafeFnMarker, T * ptr, sus::num::usize length, sus::num::usize capacity) noexcept
- public constexpr T * grow_to_internal_check_cap(sus::num::usize additional) noexcept
- public inline constexpr bool has_iterators() const noexcept
- public constexpr VecIntoIter<T> into_iter() && noexcept
- public inline constexpr bool is_alloced() const noexcept
- public inline constexpr bool is_moved_from() const noexcept
- public constexpr Slice<T> operator Slice<type-parameter-0-0>() const & noexcept
- public constexpr Slice<T> operator Slice<type-parameter-0-0>() &&
- public constexpr Slice<T> operator Slice<type-parameter-0-0>() & noexcept
- public constexpr SliceMut<T> operator SliceMut<type-parameter-0-0>() & noexcept
- public constexpr void push_with_capacity_internal(const T & t) noexcept
- public constexpr void push_with_capacity_internal(T && t) noexcept
- public constexpr T * reserve_allocated_internal(sus::num::usize additional) noexcept
- public constexpr T * reserve_exact_internal(sus::num::usize additional) noexcept
- public constexpr T * reserve_internal(sus::num::usize additional) noexcept
- public static constexpr Vec<T> with_capacity(sus::num::usize capacity) noexcept
Methods
¶template <class... Ts>
constexpr Vec<T>(Ts&&... values) noexcept
template <class... Ts>
constexpr Vec<T>(Ts&&... values) noexcept
Description
Constructs a `Vec`, which constructs objects of type `T` from the given values. This constructor also satisfies `sus::construct::Default` by accepting no arguments to create an empty `Vec`. The vector will be able to hold at least the elements created from the arguments. This method is allowed to allocate for more elements than needed. If no arguments are passed, it creates an empty `Vec` and will not allocate.
Declared at: sus/collections/vec.h:126
Templates
- Ts
Parameters
- Ts&&... values
¶constexpr Vec<T>(::sus::marker::EmptyMarker)
constexpr Vec<T>(::sus::marker::EmptyMarker)
Description
Constructs an empty `Vec`. This constructor is implicit so that using the [`EmptyMarker`]( $sus::marker::EmptyMarker) allows the caller to avoid spelling out the full `Vec` type. #[doc.overloads=empty]
Declared at: sus/collections/vec.h:113
Parameters
¶constexpr Vec<T>(
sus::collections::Vec::WithCapacity,
std::allocator<T> alloc,
sus::num::usize cap)
constexpr Vec<T>(
sus::collections::Vec::WithCapacity,
std::allocator<T> alloc,
sus::num::usize cap)
Declared at: sus/collections/vec.h:858
Parameters
- sus::collections::Vec::WithCapacity
- std::allocator<T> alloc
- sus::num::usize cap
¶constexpr Vec<T>(sus::collections::Vec::FromParts,
std::allocator<T> alloc,
sus::num::usize cap,
T* ptr,
sus::num::usize len)
constexpr Vec<T>(sus::collections::Vec::FromParts,
std::allocator<T> alloc,
sus::num::usize cap,
T* ptr,
sus::num::usize len)
Declared at: sus/collections/vec.h:849
Parameters
- sus::collections::Vec::FromParts
- std::allocator<T> alloc
- sus::num::usize cap
- T* ptr
- sus::num::usize len
¶constexpr T* alloc_internal_check_cap(
sus::num::usize cap) noexcept
constexpr T* alloc_internal_check_cap(
sus::num::usize cap) noexcept
Description
Requires that: * Vec is NOT already allocated. * Vec is in a valid state to mutate
Declared at: sus/collections/vec.h:952
Parameters
- sus::num::usize cap
¶constexpr sus::num::usize apply_growth_function(
sus::num::usize additional) const noexcept
constexpr sus::num::usize apply_growth_function(
sus::num::usize additional) const noexcept
Declared at: sus/collections/vec.h:868
Parameters
- sus::num::usize additional
¶constexpr SliceMut<T> as_mut_slice() & noexcept
constexpr SliceMut<T> as_mut_slice() & noexcept
Description
Returns a [`SliceMut`]($sus::collections::SliceMut) that references all the elements of the vector as mutable references.
Declared at: sus/collections/vec.h:682
¶constexpr void destroy_storage_objects()
constexpr void destroy_storage_objects()
Declared at: sus/collections/vec.h:878
¶constexpr void free_storage()
constexpr void free_storage()
Declared at: sus/collections/vec.h:884
¶static constexpr Vec<T> from(
::sus::SliceMut<T> slice) noexcept
static constexpr Vec<T> from(
::sus::SliceMut<T> slice) noexcept
Description
#[doc.overloads=from.slice]
Declared at: sus/collections/vec.h:196
Parameters
- ::sus::SliceMut<T> slice
¶static constexpr Vec<T> from(
::sus::Slice<T> slice) noexcept
static constexpr Vec<T> from(
::sus::Slice<T> slice) noexcept
Description
Constructs a Vec by cloning elements out of a slice. Satisfies `sus::construct::From <Slice <T >>` and `sus::construct::From <SliceMut <T >>`. #[doc.overloads=from.slice]
Declared at: sus/collections/vec.h:188
Parameters
- ::sus::Slice<T> slice
¶static constexpr Vec<T> from_raw_parts(
::sus::marker::UnsafeFnMarker,
T* ptr,
sus::num::usize length,
sus::num::usize capacity) noexcept
static constexpr Vec<T> from_raw_parts(
::sus::marker::UnsafeFnMarker,
T* ptr,
sus::num::usize length,
sus::num::usize capacity) noexcept
Description
Creates a `Vec` directly from a pointer, a capacity, and a length. # Safety This is highly unsafe, due to the number of invariants that aren’t checked: * `ptr` must be heap allocated with the same method as Vec uses internally, which is not currently stable. (TODO: Want our own global allocator API.) The only safe way to get this pointer is from `from_raw_parts()`. * `T` needs to have an alignment no more than what `ptr` was allocated with. * The size of `T` times the `capacity` (ie. the allocated size in bytes) needs to be the same size the pointer was allocated with. * `length` needs to be less than or equal to `capacity`. * The first `length` values must be properly initialized values of type `T`. * The allocated size in bytes must be no larger than `isize::MAX`. * If `ptr` is null, then `length` and `capacity` must be `0_usize`, and vice versa.
Declared at: sus/collections/vec.h:176
Parameters
- ::sus::marker::UnsafeFnMarker
- T* ptr
- sus::num::usize length
- sus::num::usize capacity
¶constexpr T* grow_to_internal_check_cap(
sus::num::usize additional) noexcept
constexpr T* grow_to_internal_check_cap(
sus::num::usize additional) noexcept
Description
Requires that: * `cap` > `capacity()` * Vec is already allocated * Vec is in a valid state to mutate
Declared at: sus/collections/vec.h:958
Parameters
- sus::num::usize additional
¶inline constexpr bool has_iterators()
const noexcept
inline constexpr bool has_iterators()
const noexcept
Declared at: sus/collections/vec.h:970
¶constexpr VecIntoIter<T> into_iter() && noexcept
constexpr VecIntoIter<T> into_iter() && noexcept
Description
Consumes the `Vec` into an [`Iterator`]($sus::iter::Iterator) that will return ownership of each element in the same order they appear in the `Vec`.
Declared at: sus/collections/vec.h:689
¶inline constexpr bool is_alloced() const noexcept
inline constexpr bool is_alloced() const noexcept
Description
Checks if Vec has storage allocated.
Declared at: sus/collections/vec.h:961
¶inline constexpr bool is_moved_from()
const noexcept
inline constexpr bool is_moved_from()
const noexcept
Description
Checks if Vec has been moved from.
Declared at: sus/collections/vec.h:966
¶constexpr Slice<T> operator Slice<
type - parameter - 0 - 0>() const& noexcept
constexpr Slice<T> operator Slice<
type - parameter - 0 - 0>() const& noexcept
Description
Converts to a [`Slice <T >`]($sus::collections::Slice). A `Vec` can be used anywhere a [`Slice`]($sus::collections::Slice) is wanted.
Declared at: sus/collections/vec.h:811
¶constexpr Slice<T>
operator Slice<type - parameter - 0 - 0>() &&
constexpr Slice<T>
operator Slice<type - parameter - 0 - 0>() &&
Declared at: sus/collections/vec.h:816
¶constexpr Slice<T> operator Slice<
type - parameter - 0 - 0>() & noexcept
constexpr Slice<T> operator Slice<
type - parameter - 0 - 0>() & noexcept
Declared at: sus/collections/vec.h:817
¶constexpr SliceMut<T> operator SliceMut<
type - parameter - 0 - 0>() & noexcept
constexpr SliceMut<T> operator SliceMut<
type - parameter - 0 - 0>() & noexcept
Description
Converts to a [`SliceMut <T >`]($sus::collections::SliceMut). A mutable `Vec` can be used anywhere a [`SliceMut`]($sus::collections::SliceMut) is wanted.
Declared at: sus/collections/vec.h:826
¶constexpr void push_with_capacity_internal(
const T& t) noexcept
constexpr void push_with_capacity_internal(
const T& t) noexcept
Description
Requires that there is capacity present for `t` already, and that Vec is in a valid state to mutate.
Declared at: sus/collections/vec.h:892
Parameters
- const T& t
¶constexpr void push_with_capacity_internal(
T&& t) noexcept
constexpr void push_with_capacity_internal(
T&& t) noexcept
Declared at: sus/collections/vec.h:896
Parameters
- T&& t
¶constexpr T* reserve_allocated_internal(
sus::num::usize additional) noexcept
constexpr T* reserve_allocated_internal(
sus::num::usize additional) noexcept
Description
Requires that: * Vec is already allocated. * Vec is in a valid state to mutate
Declared at: sus/collections/vec.h:937
Parameters
- sus::num::usize additional
¶constexpr T* reserve_exact_internal(
sus::num::usize additional) noexcept
constexpr T* reserve_exact_internal(
sus::num::usize additional) noexcept
Description
Requires that: * Vec is in a valid state to mutate
Declared at: sus/collections/vec.h:920
Parameters
- sus::num::usize additional
¶constexpr T* reserve_internal(
sus::num::usize additional) noexcept
constexpr T* reserve_internal(
sus::num::usize additional) noexcept
Description
Requires that: * Vec is in a valid state to mutate
Declared at: sus/collections/vec.h:903
Parameters
- sus::num::usize additional
¶static constexpr Vec<T> with_capacity(
sus::num::usize capacity) noexcept
static constexpr Vec<T> with_capacity(
sus::num::usize capacity) noexcept
Description
Creates a `Vec` with at least the specified capacity. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than capacity. If capacity is 0, the vector will not allocate. It is important to note that although the returned vector has the minimum capacity specified, the vector will have a zero length. A `Vec <T >` can be implicitly converted to a `Slice <T >`. If it is not const, it can also be converted to a `SliceMut <T >`. # Panics Panics if the capacity exceeds `isize::MAX` bytes.
Declared at: sus/collections/vec.h:149
Parameters
- sus::num::usize capacity