‘Limited’ vector, wrapper around std::array<>
which keeps track of its current size.
More...
#include <limvec.h>
Public Types | |
typedef Data::const_iterator | ConstIter |
Const iterator. More... | |
typedef std::array< Type, max > | Data |
Data type. More... | |
typedef Data::iterator | Iter |
Iterator type. More... | |
using | value_type = Type |
Underlying type. More... | |
Public Member Functions | |
MemoryUsage::MemorySize | allocSize () const |
Returns the size in bytes allocated by its children. More... | |
Iter | begin () |
Iterator to begin of storage. More... | |
ConstIter | begin () const |
const Iterator to begin of storage More... | |
Index | capacity () const |
Maximal number of elements. More... | |
ConstIter | cbegin () const |
const Iterator to begin of storage More... | |
ConstIter | cend () const |
const Iterator one past the end of storage More... | |
void | clear () |
Removes all elements from the vector by resetting used to 0. More... | |
Type * | data () |
pointer to the storage. More... | |
Type const * | data () const |
const pointer to the storage. More... | |
Iter | end () |
Iterator one past the end of storage. More... | |
ConstIter | end () const |
const Iterator one past the end of storage More... | |
LimVec ()=default | |
Default ctor, zero elements in use. More... | |
LimVec (Index used_) | |
Ctor declaring the first used_ elements in use. More... | |
LimVec (LimVec &&)=default | |
Move ctor. More... | |
LimVec (LimVec const &)=default | |
Copy ctor. More... | |
LimVec (std::initializer_list< Type > &&v) | |
List move initializer. More... | |
LimVec (std::initializer_list< Type > const &v) | |
List copy initializer. More... | |
LimVec (std::vector< Type > &&v) | |
Vector move initializer. More... | |
LimVec (std::vector< Type > const &v) | |
Vector copy initializer. More... | |
template<typename Container , std::enable_if_t< std::is_same_v< typename Container::value_type, Type >, int > = 0> | |
operator Container () const | |
Conversion to an arbitrary container of the same type. More... | |
operator Data () | |
Conversion to the underlying array type. More... | |
bool | operator!= (LimVec const &other) const |
Compare any of the used elements for inequality. More... | |
bool | operator< (LimVec const &b) const |
Returns true if the first element of *this that is not equal to the corresponding element of b is smaller than that element. More... | |
LimVec & | operator= (LimVec &&)=default |
Move assignment op. More... | |
LimVec & | operator= (LimVec const &)=default |
Copy assignment op. More... | |
LimVec & | operator= (std::initializer_list< Type > &&v) |
Move assignment op from init list. More... | |
LimVec & | operator= (std::initializer_list< Type > const &v) |
Copy assignment op from init list. More... | |
LimVec & | operator= (std::vector< Type > &&v) |
Move assignment op from vector. More... | |
LimVec & | operator= (std::vector< Type > const &v) |
Copy assignment op from vector. More... | |
bool | operator== (LimVec const &other) const |
Compare used elements for equality. More... | |
Type & | operator[] (Index i) |
Element access. More... | |
Type const & | operator[] (Index i) const |
Element access (const) More... | |
void | push_back (Type &&val) |
Add element at the end by moving. More... | |
void | push_back (Type const &val) |
Add element at the end by copying. More... | |
void | reserve (Index) const |
Dummy, does nothing, as we are fixed-length. More... | |
void | resize (Index new_size) |
Resets the used value to new_size , effectively resizing the apparent vector. More... | |
template<typename Archive > | |
void | serialize (Archive &ar, const unsigned int in_version) |
Boost serialisation. More... | |
Index | size () const |
Number of used elements. More... | |
Explicitly deleted operators to avoid wrong overloads. | |
LimVec & | operator= (unsigned int)=delete |
Deleted overload. More... | |
LimVec & | operator= (int)=delete |
Deleted overload. More... | |
LimVec & | operator= (unsigned long long)=delete |
Deleted overload. More... | |
LimVec & | operator= (long long)=delete |
Deleted overload. More... | |
Static Public Attributes | |
static constexpr unsigned int | version = 1 |
Boost serialisation version. More... | |
Private Attributes | |
Data | storage |
array holding the actual data More... | |
MaxType | used = 0 |
counter tracking the number of used elements More... | |
‘Limited’ vector, wrapper around std::array<>
which keeps track of its current size.
Intended to be used largely like a vector, just with more data locality and better space usage if individual elements are small – a std::vector<>
takes at least 24 bytes plus however many are to be allocated, whereas for example a maximal-2-element LimVec of 4-byte sized elements would only take 9 bytes (padded 10).
Type | contained type |
max | maximal number of contained elements |
MaxType | type used to count the number of used elements |