geomc 1.0
A c++ linear algebra template library
Loading...
Searching...
No Matches
SmallStorage< T, N > Struct Template Reference

Array storage which does not allocate from the heap unless the requested size is larger than a threshold, N. More...

#include <geomc/SmallStorage.h>

Public Member Functions

 SmallStorage ()
 Construct an array with zero items, but capcity for N.
 
 SmallStorage (const SmallStorage< T, N > &other)
 Construct an array containing the elements of other.
 
 SmallStorage (const T &value, size_t count)
 Construct an array containing count copies of value.
 
 SmallStorage (const T *items, size_t n)
 Construct an array of n items by copy-constructing the items from the given array.
 
 SmallStorage (size_t n)
 Construct an array containing n default-constructed items.
 
 SmallStorage (SmallStorage< T, N > &&other)
 Move the contents of other to this array.
 
 SmallStorage (std::initializer_list< T > items)
 Construct an array by move-constructing the items in the given initializer list.
 
 ~SmallStorage ()
 Destroy this array and its contents.
 
T & back ()
 Access the last item in the array.
 
const T & back () const
 Access the last const item in the array.
 
T * begin ()
 
const T * begin () const
 
size_t capacity () const
 Return the number of items the array can contain without reallocating.
 
void clear ()
 Remove all the items from the array.
 
T * data ()
 Return a pointer to the underlying array that backs this SmallStorage.
 
const T * data () const
 Return a const pointer to the underlying array that backs this SmallStorage.
 
template<typename... Args>
T & emplace_back (Args &&... args)
 Construct a new item at the end of the array from the given constructor arguments.
 
bool empty () const
 Return true iff the array contains no items.
 
T * end ()
 
const T * end () const
 
T & front ()
 Access the first item in the array.
 
const T & front () const
 Access the first const item in the array.
 
SmallStorage< T, N > & operator= (const SmallStorage< T, N > &other)
 Copy the contents of other into this array.
 
SmallStorage< T, N > & operator= (SmallStorage< T, N > &&other)
 Move the contents of other into this array.
 
bool operator== (const SmallStorage< T, N > &other) const
 Return true iff all the items in this and other are equal and in equal order.
 
T & operator[] (size_t i)
 Access the ith item.
 
const T & operator[] (size_t i) const
 Access the ith const item.
 
std::optional< T > pop_back ()
 Remove the last item from the array and return it, if one exists.
 
T & push_back (const T &item)
 Add a copy of the given item to the end of the array, increasing its size by 1.
 
void reserve (size_t count)
 Ensure there is capacity for at least count items without reallocating.
 
template<typename... Args>
void resize (size_t count, const Args &... args)
 
size_t size () const
 Return the number of items in the array.
 

Static Public Member Functions

static constexpr size_t static_capacity ()
 Return the number of items the array can hold without allocating from the heap.
 

Static Public Attributes

static constexpr size_t StaicCapacity = N
 

Detailed Description

template<typename T, size_t N>
struct geom::SmallStorage< T, N >

Array storage which does not allocate from the heap unless the requested size is larger than a threshold, N.

Template Parameters
TElement type.
NMaximum stack-allocated array size.

Useful when a required buffer is expected to be small, but there is no explicit upper bound on the possible size. This allows the stack to be used in the majority case, only deferring to heap allocation when unusually large buffers are needed.

On assignment or copy, reallocations will be avoided if the existing buffer is already the correct size.

This buffer will always stack-allocate a buffer of size N (it will simply not be used when a heap allocation is necessary).

Member Function Documentation

◆ resize()

template<typename T, size_t N>
template<typename... Args>
void resize ( size_t count,
const Args &... args )
inline

Change the number of items in the array; constructing new items from the arguments if any are provided, and destroying any excess items.


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