tlx
SimpleVector< ValueType, Mode > Class Template Reference

Simpler non-growing vector without initialization. More...

#include <simple_vector.hpp>

Public Types

using value_type = ValueType
 
using size_type = size_t
 
using iterator = value_type *
 
using const_iterator = const value_type *
 
using reference = value_type &
 
using const_reference = const value_type &
 

Public Member Functions

 SimpleVector ()
 allocate empty simple vector More...
 
 SimpleVector (const size_type &sz)
 allocate vector's memory More...
 
 SimpleVector (const SimpleVector &)=delete
 non-copyable: delete copy-constructor More...
 
SimpleVectoroperator= (const SimpleVector &)=delete
 non-copyable: delete assignment operator More...
 
 SimpleVector (SimpleVector &&v) noexcept
 move-constructor More...
 
SimpleVectoroperator= (SimpleVector &&v) noexcept
 move-assignment More...
 
void swap (SimpleVector &obj) noexcept
 swap vector with another one More...
 
 ~SimpleVector ()
 delete vector More...
 
iterator data () noexcept
 return iterator to beginning of vector More...
 
const_iterator data () const noexcept
 return iterator to beginning of vector More...
 
size_type size () const noexcept
 return number of items in vector More...
 
iterator begin () noexcept
 return mutable iterator to first element More...
 
const_iterator begin () const noexcept
 return constant iterator to first element More...
 
const_iterator cbegin () const noexcept
 return constant iterator to first element More...
 
iterator end () noexcept
 return mutable iterator beyond last element More...
 
const_iterator end () const noexcept
 return constant iterator beyond last element More...
 
const_iterator cend () const noexcept
 return constant iterator beyond last element More...
 
reference operator[] (size_type i) noexcept
 return the i-th position of the vector More...
 
const_reference operator[] (size_type i) const noexcept
 return constant reference to the i-th position of the vector More...
 
void resize (size_type new_size)
 resize the array to contain exactly new_size items More...
 
void destroy ()
 deallocate contained array More...
 
void fill (const value_type &v=value_type()) noexcept
 Zero the whole array content. More...
 

Protected Attributes

size_type size_
 size of allocated memory More...
 
value_typearray_
 pointer to allocated memory area More...
 

Static Private Member Functions

static ValueType * create_array (size_t size)
 
static void destroy_array (ValueType *array, size_t size)
 

Detailed Description

template<typename ValueType, SimpleVectorMode Mode = SimpleVectorMode::Normal>
class tlx::SimpleVector< ValueType, Mode >

Simpler non-growing vector without initialization.

SimpleVector can be used a replacement for std::vector when only a non-growing array of simple types is needed. The advantages of SimpleVector are that it does not initilize memory for POD types (-> faster), while normal structs are supported as well if default-contractible. The simple pointer types allow faster compilation and is less error prone to copying and other problems.

Definition at line 62 of file simple_vector.hpp.

Member Typedef Documentation

◆ const_iterator

using const_iterator = const value_type *

Definition at line 79 of file simple_vector.hpp.

◆ const_reference

using const_reference = const value_type&

Definition at line 81 of file simple_vector.hpp.

◆ iterator

using iterator = value_type *

Definition at line 78 of file simple_vector.hpp.

◆ reference

Definition at line 80 of file simple_vector.hpp.

◆ size_type

using size_type = size_t

Definition at line 66 of file simple_vector.hpp.

◆ value_type

using value_type = ValueType

Definition at line 65 of file simple_vector.hpp.

Constructor & Destructor Documentation

◆ SimpleVector() [1/4]

SimpleVector ( )
inline

allocate empty simple vector

Definition at line 85 of file simple_vector.hpp.

◆ SimpleVector() [2/4]

SimpleVector ( const size_type sz)
inlineexplicit

allocate vector's memory

Definition at line 90 of file simple_vector.hpp.

◆ SimpleVector() [3/4]

SimpleVector ( const SimpleVector< ValueType, Mode > &  )
delete

non-copyable: delete copy-constructor

◆ SimpleVector() [4/4]

SimpleVector ( SimpleVector< ValueType, Mode > &&  v)
inlinenoexcept

move-constructor

Definition at line 102 of file simple_vector.hpp.

◆ ~SimpleVector()

~SimpleVector ( )
inline

delete vector

Definition at line 122 of file simple_vector.hpp.

Member Function Documentation

◆ begin() [1/2]

const_iterator begin ( ) const
inlinenoexcept

return constant iterator to first element

Definition at line 144 of file simple_vector.hpp.

◆ begin() [2/2]

iterator begin ( )
inlinenoexcept

return mutable iterator to first element

Definition at line 140 of file simple_vector.hpp.

◆ cbegin()

const_iterator cbegin ( ) const
inlinenoexcept

return constant iterator to first element

Definition at line 148 of file simple_vector.hpp.

◆ cend()

const_iterator cend ( ) const
inlinenoexcept

return constant iterator beyond last element

Definition at line 161 of file simple_vector.hpp.

◆ create_array()

static ValueType* create_array ( size_t  size)
inlinestaticprivate

Definition at line 202 of file simple_vector.hpp.

◆ data() [1/2]

const_iterator data ( ) const
inlinenoexcept

return iterator to beginning of vector

Definition at line 131 of file simple_vector.hpp.

◆ data() [2/2]

iterator data ( )
inlinenoexcept

return iterator to beginning of vector

Definition at line 127 of file simple_vector.hpp.

◆ destroy()

void destroy ( )
inline

deallocate contained array

Definition at line 190 of file simple_vector.hpp.

◆ destroy_array()

static void destroy_array ( ValueType *  array,
size_t  size 
)
inlinestaticprivate

Definition at line 217 of file simple_vector.hpp.

◆ end() [1/2]

const_iterator end ( ) const
inlinenoexcept

return constant iterator beyond last element

Definition at line 157 of file simple_vector.hpp.

◆ end() [2/2]

iterator end ( )
inlinenoexcept

return mutable iterator beyond last element

Definition at line 153 of file simple_vector.hpp.

◆ fill()

void fill ( const value_type v = value_type())
inlinenoexcept

Zero the whole array content.

Definition at line 197 of file simple_vector.hpp.

◆ operator=() [1/2]

SimpleVector& operator= ( const SimpleVector< ValueType, Mode > &  )
delete

non-copyable: delete assignment operator

◆ operator=() [2/2]

SimpleVector& operator= ( SimpleVector< ValueType, Mode > &&  v)
inlinenoexcept

move-assignment

Definition at line 107 of file simple_vector.hpp.

◆ operator[]() [1/2]

const_reference operator[] ( size_type  i) const
inlinenoexcept

return constant reference to the i-th position of the vector

Definition at line 170 of file simple_vector.hpp.

◆ operator[]() [2/2]

reference operator[] ( size_type  i)
inlinenoexcept

return the i-th position of the vector

Definition at line 166 of file simple_vector.hpp.

◆ resize()

void resize ( size_type  new_size)
inline

resize the array to contain exactly new_size items

Definition at line 175 of file simple_vector.hpp.

◆ size()

size_type size ( ) const
inlinenoexcept

return number of items in vector

Definition at line 135 of file simple_vector.hpp.

◆ swap()

void swap ( SimpleVector< ValueType, Mode > &  obj)
inlinenoexcept

swap vector with another one

Definition at line 116 of file simple_vector.hpp.

Member Data Documentation

◆ array_

value_type* array_
protected

pointer to allocated memory area

Definition at line 73 of file simple_vector.hpp.

◆ size_

size_type size_
protected

size of allocated memory

Definition at line 70 of file simple_vector.hpp.


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