ONE - On-device Neural Engine
Loading...
Searching...
No Matches
adt::small_vector< T, Capacity > Class Template Reference

vector with cheap memory allocation More...

#include <SmallVector.h>

Public Types

using value_type = T
 
using reference = T &
 
using iterator = T *
 
using const_iterator = const T *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using size_type = size_t
 

Public Member Functions

template<typename It >
 small_vector (It begin, It end)
 
 small_vector (size_t size, value_type initializer=value_type())
 
 small_vector ()
 
 small_vector (std::initializer_list< value_type > l)
 
size_t size () const noexcept
 
constexpr size_t capacity () const
 
void resize (size_t new_size) noexcept
 resize to given new size
 
reference operator[] (size_t idx) noexcept
 
constexpr value_type operator[] (size_t idx) const noexcept
 
iterator begin () noexcept
 
iterator end () noexcept
 
reverse_iterator rbegin () noexcept
 
reverse_iterator rend () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator rend () const noexcept
 
void push_back (const value_type &e) noexcept
 
void push_back (value_type &&e) noexcept
 

Detailed Description

template<typename T, size_t Capacity>
class adt::small_vector< T, Capacity >

vector with cheap memory allocation

Template Parameters
Ttype of elements
Capacitymaximum number of elements
Note
much like std::array, but tracks number of used elements. Stored in stack

Definition at line 33 of file SmallVector.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::const_iterator = const T *

Definition at line 39 of file SmallVector.h.

◆ const_reverse_iterator

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 41 of file SmallVector.h.

◆ iterator

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::iterator = T *

Definition at line 38 of file SmallVector.h.

◆ reference

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::reference = T &

Definition at line 37 of file SmallVector.h.

◆ reverse_iterator

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 40 of file SmallVector.h.

◆ size_type

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::size_type = size_t

Definition at line 42 of file SmallVector.h.

◆ value_type

template<typename T , size_t Capacity>
using adt::small_vector< T, Capacity >::value_type = T

Definition at line 36 of file SmallVector.h.

Constructor & Destructor Documentation

◆ small_vector() [1/4]

template<typename T , size_t Capacity>
template<typename It >
adt::small_vector< T, Capacity >::small_vector ( It  begin,
It  end 
)
inline

Definition at line 44 of file SmallVector.h.

44 : _size(std::distance(begin, end))
45 {
46 assert(_size <= Capacity);
47 std::copy(begin, end, this->begin());
48 }
iterator begin() noexcept
iterator end() noexcept

References adt::small_vector< T, Capacity >::begin(), and adt::small_vector< T, Capacity >::end().

◆ small_vector() [2/4]

template<typename T , size_t Capacity>
adt::small_vector< T, Capacity >::small_vector ( size_t  size,
value_type  initializer = value_type() 
)
inlineexplicit

Definition at line 50 of file SmallVector.h.

50 : _size(size)
51 {
52 assert(_size <= Capacity);
53 std::fill(begin(), end(), initializer);
54 }
size_t size() const noexcept
Definition SmallVector.h:67

References adt::small_vector< T, Capacity >::begin(), and adt::small_vector< T, Capacity >::end().

◆ small_vector() [3/4]

template<typename T , size_t Capacity>
adt::small_vector< T, Capacity >::small_vector ( )
inlineexplicit

Definition at line 56 of file SmallVector.h.

56: _size(0) {}

◆ small_vector() [4/4]

template<typename T , size_t Capacity>
adt::small_vector< T, Capacity >::small_vector ( std::initializer_list< value_type l)
inline

Definition at line 58 of file SmallVector.h.

58 : _size(l.size())
59 {
60 assert(_size <= Capacity);
61 std::copy(std::begin(l), std::end(l), begin());
62 }

References adt::small_vector< T, Capacity >::begin().

Member Function Documentation

◆ begin() [1/2]

template<typename T , size_t Capacity>
const_iterator adt::small_vector< T, Capacity >::begin ( ) const
inlinenoexcept

Definition at line 113 of file SmallVector.h.

113{ return std::begin(_storage); }

◆ begin() [2/2]

template<typename T , size_t Capacity>
iterator adt::small_vector< T, Capacity >::begin ( )
inlinenoexcept

◆ capacity()

template<typename T , size_t Capacity>
constexpr size_t adt::small_vector< T, Capacity >::capacity ( ) const
inlineconstexpr
Returns
maximum number of elements this vector can hold

Definition at line 72 of file SmallVector.h.

72{ return Capacity; }

◆ end() [1/2]

template<typename T , size_t Capacity>
const_iterator adt::small_vector< T, Capacity >::end ( ) const
inlinenoexcept

Definition at line 114 of file SmallVector.h.

114{ return _storage + _size; }

◆ end() [2/2]

template<typename T , size_t Capacity>
iterator adt::small_vector< T, Capacity >::end ( )
inlinenoexcept

◆ operator[]() [1/2]

template<typename T , size_t Capacity>
constexpr value_type adt::small_vector< T, Capacity >::operator[] ( size_t  idx) const
inlineconstexprnoexcept
Returns
value of element at position idx

Definition at line 100 of file SmallVector.h.

101 {
102 // assert on the same line since c++11 does not allow multi-line constexpr functions
103 return assert(idx < _size), _storage[idx];
104 }

◆ operator[]() [2/2]

template<typename T , size_t Capacity>
reference adt::small_vector< T, Capacity >::operator[] ( size_t  idx)
inlinenoexcept
Returns
reference to the element at position idx

Definition at line 91 of file SmallVector.h.

92 {
93 assert(idx < _size);
94 return _storage[idx];
95 }

◆ push_back() [1/2]

template<typename T , size_t Capacity>
void adt::small_vector< T, Capacity >::push_back ( const value_type e)
inlinenoexcept

Definition at line 119 of file SmallVector.h.

120 {
121 assert(_size < Capacity);
122 _storage[_size++] = e;
123 }

◆ push_back() [2/2]

template<typename T , size_t Capacity>
void adt::small_vector< T, Capacity >::push_back ( value_type &&  e)
inlinenoexcept

Definition at line 125 of file SmallVector.h.

126 {
127 assert(_size < Capacity);
128 _storage[_size++] = std::move(e);
129 }

◆ rbegin() [1/2]

template<typename T , size_t Capacity>
const_reverse_iterator adt::small_vector< T, Capacity >::rbegin ( ) const
inlinenoexcept

Definition at line 116 of file SmallVector.h.

116{ return reverse_iterator{end()}; }
std::reverse_iterator< iterator > reverse_iterator
Definition SmallVector.h:40

References adt::small_vector< T, Capacity >::end().

◆ rbegin() [2/2]

template<typename T , size_t Capacity>
reverse_iterator adt::small_vector< T, Capacity >::rbegin ( )
inlinenoexcept

Definition at line 109 of file SmallVector.h.

109{ return reverse_iterator{end()}; }

References adt::small_vector< T, Capacity >::end().

◆ rend() [1/2]

template<typename T , size_t Capacity>
const_reverse_iterator adt::small_vector< T, Capacity >::rend ( ) const
inlinenoexcept

Definition at line 117 of file SmallVector.h.

117{ return reverse_iterator{begin()}; }

References adt::small_vector< T, Capacity >::begin().

◆ rend() [2/2]

template<typename T , size_t Capacity>
reverse_iterator adt::small_vector< T, Capacity >::rend ( )
inlinenoexcept

Definition at line 110 of file SmallVector.h.

110{ return reverse_iterator{begin()}; }

References adt::small_vector< T, Capacity >::begin().

◆ resize()

template<typename T , size_t Capacity>
void adt::small_vector< T, Capacity >::resize ( size_t  new_size)
inlinenoexcept

resize to given new size

Note
if new size is greater than current size, new elements are default-initialized

Definition at line 78 of file SmallVector.h.

79 {
80 assert(new_size <= Capacity);
81 if (new_size > _size)
82 {
83 std::fill(_storage + _size, _storage + new_size, T());
84 }
85 _size = new_size;
86 }

Referenced by mir::Index::resize(), and mir::Shape::resize().

◆ size()

template<typename T , size_t Capacity>
size_t adt::small_vector< T, Capacity >::size ( ) const
inlinenoexcept
Returns
current size

Definition at line 67 of file SmallVector.h.

67{ return _size; }

Referenced by mir::Index::at(), mir::Index::at(), mir::Shape::dim(), mir::Shape::dim(), adt::operator==(), mir::Index::rank(), and mir::Shape::rank().


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