AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ASmallVector< StoredType, StaticVectorSize, Allocator > Class Template Reference

Vector-like container consisting of few elements on stack and switches to dynamic allocation vector if needed. More...

Detailed Description

template<typename StoredType, std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
class ASmallVector< StoredType, StaticVectorSize, Allocator >

Vector-like container consisting of few elements on stack and switches to dynamic allocation vector if needed.

Template Parameters
StoredTypestored type
StaticVectorSizehow many elements can be stored without dynamic allocation
Allocatorallocation

Vector-like container optimized for the case when it contains up to StaticVectorSize in place, avoiding dynamic allocation. In case when element count exceeds StaticVectorSize, ASmallVector seamlessly switches to traditional dynamic allocation vector.

Examples
/github/workspace/aui.views/src/AUI/View/AView.h.

Public Types

using iterator = StoredType *
 
using const_iterator = const StoredType *
 
using reference = StoredType &
 
using const_reference = const StoredType &
 
using value = StoredType
 

Public Member Functions

 ASmallVector (ASmallVector &&rhs) noexcept
 
constexpr StoredType * data () noexcept
 
constexpr const StoredType * data () const noexcept
 
constexpr iterator begin () noexcept
 
constexpr const_iterator begin () const noexcept
 
constexpr iterator end () noexcept
 
constexpr const_iterator end () const noexcept
 
constexpr StoredType & front () noexcept
 
constexpr StoredType & back () noexcept
 
constexpr const StoredType & front () const noexcept
 
constexpr const StoredType & back () const noexcept
 
constexpr void push_back (StoredType value) noexcept
 
constexpr void push_front (StoredType value) noexcept
 
constexpr void pop_back () noexcept
 
constexpr void pop_front () noexcept
 
constexpr StoredType & operator[] (std::size_t index) noexcept
 
constexpr StoredType & operator[] (std::size_t index) const noexcept
 
constexpr bool empty () const noexcept
 
constexpr void clear () noexcept
 
std::size_t size () const noexcept
 
bool isInplaceAllocated () const noexcept
 
template<typename OtherIterator >
constexpr iterator insert (iterator at, OtherIterator begin, OtherIterator end)
 
constexpr iterator erase (iterator begin, iterator end) noexcept
 
constexpr iterator insert (iterator at, StoredType value)
 
constexpr iterator erase (iterator at)
 
template<typename OtherContainer >
iterator insertAll (const OtherContainer &c) noexcept
 
template<typename OtherContainer >
iterator insertAll (OtherContainer &&c) noexcept
 
template<typename OtherContainer >
iterator insertAll (iterator at, const OtherContainer &c) noexcept
 
template<typename OtherContainer >
iterator insertAll (iterator at, OtherContainer &&c) noexcept
 
void removeAll (const StoredType &item) noexcept
 
template<typename T , aui::mapper< const StoredType &, const T & > Projection>
void removeAll (const T &item, Projection projection) noexcept
 
void removeFirst (const StoredType &item) noexcept
 
template<typename OtherContainer >
bool isSubsetOf (const OtherContainer &c) const noexcept
 
bool contains (const StoredType &value) const noexcept
 
std::size_t sizeInBytes () const noexcept
 
StoredType & at (std::size_t index)
 
const StoredType & at (std::size_t index) const
 
selfoperator<< (const StoredType &rhs) noexcept
 
selfoperator<< (StoredType &&rhs) noexcept
 
template<typename OtherContainer , std::enable_if_t<!std::is_convertible_v< OtherContainer, StoredType >, bool > = true>
selfoperator<< (const OtherContainer &c) noexcept
 
template<typename OtherContainer , std::enable_if_t<!std::is_convertible_v< OtherContainer, StoredType >, bool > = true>
selfoperator<< (OtherContainer &&c) noexcept
 
StoredType & first () noexcept
 
const StoredType & first () const noexcept
 
StoredType & last () noexcept
 
const StoredType & last () const noexcept
 
size_t indexOf (const StoredType &value) const noexcept
 
void sort () noexcept
 
template<typename Comparator >
void sort (Comparator &&comparator) noexcept
 
template<aui::predicate< StoredType > Predicate>
StoredType * findIf (Predicate &&predicate) noexcept
 Finds element by predicate. More...
 
template<typename T , aui::mapper< const StoredType &, const T & > Projection>
StoredType * findIf (const T &value, Projection &&projection) noexcept
 Finds element by value. More...
 
void removeAt (size_t index) noexcept
 
template<typename Predicate >
void removeIf (Predicate &&predicate) noexcept
 
ASet< StoredType > toSet () const noexcept
 
template<aui::invocable< const StoredType & > UnaryOperation>
auto map (UnaryOperation &&transformer) const -> AVector< decltype(transformer(std::declval< StoredType >()))>
 
template<aui::invocable< const StoredType & > UnaryOperation>
auto toMap (UnaryOperation &&transformer) const -> AMap< decltype(transformer(std::declval< StoredType >()).first), decltype(transformer(std::declval< StoredType >()).second)>
 
template<aui::invocable< StoredType & > UnaryOperation>
auto toMap (UnaryOperation &&transformer) -> AMap< decltype(transformer(std::declval< StoredType >()).first), decltype(transformer(std::declval< StoredType >()).second)>
 
template<aui::predicate< const StoredType & > Predicate>
self filter (Predicate &&predicate)
 

Static Public Member Functions

template<aui::incrementable Iterator, aui::invocable< decltype(*std::declval< Iterator >())> UnaryOperation>
static auto fromRange (aui::range< Iterator > range, UnaryOperation &&transformer) -> AVector< decltype(transformer(range.first()))>
 Constructs a new vector of transformed items of the range. More...
 

Protected Types

using self = ASmallVector
 
using super = self
 
using StaticVector = AStaticVector< StoredType, StaticVectorSize >
 
using DynamicVector = ADynamicVector< StoredType >
 

Member Function Documentation

◆ contains()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
bool ASmallVector< StoredType, StaticVectorSize, Allocator >::contains ( const StoredType &  value) const
inlinenoexcept
Returns
true if container contains an element, false otherwise.

◆ findIf() [1/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename T , aui::mapper< const StoredType &, const T & > Projection>
StoredType * ASmallVector< StoredType, StaticVectorSize, Allocator >::findIf ( const T &  value,
Projection &&  projection 
)
inlinenoexcept

Finds element by value.

Parameters
valuevalue
projectioncallable that transforms const StoredType& to const T&. Can be any operator() cappable object, including lambda and pointer-to-member.
Returns
Pointer to the value on which the predicate returned true, nullptr otherwise

◆ findIf() [2/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<aui::predicate< StoredType > Predicate>
StoredType * ASmallVector< StoredType, StaticVectorSize, Allocator >::findIf ( Predicate &&  predicate)
inlinenoexcept

Finds element by predicate.

Parameters
predicatepredicate
Returns
Pointer to the value on which the predicate returned true, nullptr otherwise

◆ first() [1/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
const StoredType & ASmallVector< StoredType, StaticVectorSize, Allocator >::first ( ) const
inlinenoexcept
Sneaky assertions
Container is not empty.
Returns
the first element.

◆ first() [2/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
StoredType & ASmallVector< StoredType, StaticVectorSize, Allocator >::first ( )
inlinenoexcept
Sneaky assertions
Container is not empty.
Returns
the first element.

◆ fromRange()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<aui::incrementable Iterator, aui::invocable< decltype(*std::declval< Iterator >())> UnaryOperation>
static auto ASmallVector< StoredType, StaticVectorSize, Allocator >::fromRange ( aui::range< Iterator >  range,
UnaryOperation &&  transformer 
) -> AVector<decltype(transformer(range.first()))>
inlinestatic

Constructs a new vector of transformed items of the range.

Parameters
rangeitems to transform from.
transformertransformer function.
Returns
A new vector.

◆ indexOf()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
size_t ASmallVector< StoredType, StaticVectorSize, Allocator >::indexOf ( const StoredType &  value) const
inlinenoexcept
Parameters
valueelement to find.
Returns
index of the specified element. If element is not found, -1 is returned.

◆ insertAll() [1/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer >
iterator ASmallVector< StoredType, StaticVectorSize, Allocator >::insertAll ( const OtherContainer &  c)
inlinenoexcept

Inserts all values of the specified container to the end.

Template Parameters
OtherContainerother container type.
Parameters
cother container
Returns
iterator pointing to the first element inserted.

◆ insertAll() [2/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer >
iterator ASmallVector< StoredType, StaticVectorSize, Allocator >::insertAll ( iterator  at,
const OtherContainer &  c 
)
inlinenoexcept

Inserts all values of the specified container.

Template Parameters
OtherContainerother container type.
Parameters
atposition to insert at.
cother container
Returns
iterator pointing to the first element inserted.

◆ insertAll() [3/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer >
iterator ASmallVector< StoredType, StaticVectorSize, Allocator >::insertAll ( iterator  at,
OtherContainer &&  c 
)
inlinenoexcept

Inserts all values of the specified container.

Template Parameters
OtherContainerother container type.
Parameters
atposition to insert at.
cother container
Returns
iterator pointing to the first element inserted.

◆ insertAll() [4/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer >
iterator ASmallVector< StoredType, StaticVectorSize, Allocator >::insertAll ( OtherContainer &&  c)
inlinenoexcept

Inserts all values of the specified container to the end.

Template Parameters
OtherContainerother container type.
Parameters
cother container
Returns
iterator pointing to the first element inserted.

◆ isSubsetOf()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer >
bool ASmallVector< StoredType, StaticVectorSize, Allocator >::isSubsetOf ( const OtherContainer &  c) const
inlinenoexcept
Returns
true if c container is a subset of this container, false otherwise.

◆ last() [1/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
const StoredType & ASmallVector< StoredType, StaticVectorSize, Allocator >::last ( ) const
inlinenoexcept
Sneaky assertions
Container is not empty.
Returns
the last element.

◆ last() [2/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
StoredType & ASmallVector< StoredType, StaticVectorSize, Allocator >::last ( )
inlinenoexcept
Sneaky assertions
Container is not empty.
Returns
the last element.

◆ operator<<() [1/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer , std::enable_if_t<!std::is_convertible_v< OtherContainer, StoredType >, bool > = true>
self & ASmallVector< StoredType, StaticVectorSize, Allocator >::operator<< ( const OtherContainer &  c)
inlinenoexcept

Shortcut to insertAll.

Parameters
rhscontainer to push
Returns
self

◆ operator<<() [2/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
self & ASmallVector< StoredType, StaticVectorSize, Allocator >::operator<< ( const StoredType &  rhs)
inlinenoexcept

Shortcut to push_back.

Parameters
rhsvalue to push
Returns
self

◆ operator<<() [3/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename OtherContainer , std::enable_if_t<!std::is_convertible_v< OtherContainer, StoredType >, bool > = true>
self & ASmallVector< StoredType, StaticVectorSize, Allocator >::operator<< ( OtherContainer &&  c)
inlinenoexcept

Shortcut to insertAll.

Parameters
rhscontainer to push
Returns
self

◆ operator<<() [4/4]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
self & ASmallVector< StoredType, StaticVectorSize, Allocator >::operator<< ( StoredType &&  rhs)
inlinenoexcept

Shortcut to push_back.

Parameters
rhsvalue to push
Returns
self

◆ removeAll() [1/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
void ASmallVector< StoredType, StaticVectorSize, Allocator >::removeAll ( const StoredType &  item)
inlinenoexcept

Removes all occurrences of item.

Parameters
itemelement to remove.

◆ removeAll() [2/2]

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename T , aui::mapper< const StoredType &, const T & > Projection>
void ASmallVector< StoredType, StaticVectorSize, Allocator >::removeAll ( const T &  item,
Projection  projection 
)
inlinenoexcept

Removes all occurrences of item with specified projection.

Parameters
itemelement to remove.
projectioncallable that transforms const StoredType& to const T&. Can be any operator() cappable object, including lambda and pointer-to-member.

◆ removeAt()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
void ASmallVector< StoredType, StaticVectorSize, Allocator >::removeAt ( size_t  index)
inlinenoexcept

Removes element at the specified index.

Sneaky assertions
index points to the existing element.
Parameters
indexindex of the element.

◆ removeFirst()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
void ASmallVector< StoredType, StaticVectorSize, Allocator >::removeFirst ( const StoredType &  item)
inlinenoexcept

Removes first occurrence of item.

Parameters
itemelement to remove.

◆ removeIf()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
template<typename Predicate >
void ASmallVector< StoredType, StaticVectorSize, Allocator >::removeIf ( Predicate &&  predicate)
inlinenoexcept

Removes element if predicate(container[i]) == true.

Parameters
predicatepredicate

◆ size()

template<typename StoredType , std::size_t StaticVectorSize, typename Allocator = std::allocator<StoredType>>
std::size_t ASmallVector< StoredType, StaticVectorSize, Allocator >::size ( ) const
inlinenoexcept
Returns
Size of the container.

#include <AUI/Common/ASmallVector.h>


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