SyTen
syten::LimVec< Type, max, MaxType, type > Class Template Reference

‘Limited’ vector, wrapper around std::array<> which keeps track of its current size. More...

#include <limvec.h>

+ Inheritance diagram for syten::LimVec< Type, max, MaxType, type >:
+ Collaboration diagram for syten::LimVec< Type, max, MaxType, type >:

Public Types

typedef Data::const_iterator ConstIter
 Const iterator. More...
 
typedef std::array< Type, maxData
 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...
 
LimVecoperator= (LimVec &&)=default
 Move assignment op. More...
 
LimVecoperator= (LimVec const &)=default
 Copy assignment op. More...
 
LimVecoperator= (std::initializer_list< Type > &&v)
 Move assignment op from init list. More...
 
LimVecoperator= (std::initializer_list< Type > const &v)
 Copy assignment op from init list. More...
 
LimVecoperator= (std::vector< Type > &&v)
 Move assignment op from vector. More...
 
LimVecoperator= (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.
LimVecoperator= (unsigned int)=delete
 Deleted overload. More...
 
LimVecoperator= (int)=delete
 Deleted overload. More...
 
LimVecoperator= (unsigned long long)=delete
 Deleted overload. More...
 
LimVecoperator= (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...
 

Detailed Description

template<typename Type, Rank max, typename MaxType = unsigned char, typename std::enable_if<(max< std::numeric_limits< MaxType >::max()), int >::type = 0>
class syten::LimVec< Type, max, MaxType, type >

‘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).

Template Parameters
Typecontained type
maxmaximal number of contained elements
MaxTypetype used to count the number of used elements

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