PLearn 0.1
|
Compile-time fixed-size vector with interface close to std::vector. More...
#include <TinyVector.h>
Public Types | |
typedef T | value_type |
Typedefs. | |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
Public Member Functions | |
iterator | begin () |
Iterators. | |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
reference | operator[] (size_type n) |
Unchecked element access. | |
const_reference | operator[] (size_type n) const |
reference | at (size_type n) |
Checked element access. | |
const_reference | at (size_type n) const |
reference | front () |
first element | |
const_reference | front () const |
reference | back () |
last element | |
const_reference | back () const |
TinyVector () | |
Constructors, etc. | |
TinyVector (size_type n, const T &val=T()) | |
template<class In > | |
void | assign (In first, In last) |
Use default copy constructor, destructor, assignment operator. | |
void | assign (size_type n, const T &val) |
n copies of val | |
void | push_back (const T &x) |
Stack operations. | |
void | pop_back () |
remove last element | |
size_type | size () const |
(list operations are NOT provided at the moment) | |
bool | empty () const |
size_type | max_size () |
void | resize (size_type sz, const T &val=T()) |
added elts init by val | |
void | reserve (size_type n) |
make room for total of n elts | |
void | swap (TinyVector &) |
Swap this with the argument. | |
void | fill (const T &) |
Fill with a constant (keeping the size constant) | |
TinyVector | copy () const |
For compatibility with TVec, copy() simply returns a copy of ourselves. | |
Private Attributes | |
T | arr [N] |
Compile-time fixed-size vector with interface close to std::vector.
A tiny vector tries to mimic (a small subset of) the interface of a built-in standard std::vector<>, but it has an additional restriction: it can hold a compile-time maximum number of elements. In exchange for this restriction, it allocates the elements of the vector within the class, which completely eliminates the need for dynamic allocation. In addition, the size of the vector is not stored explicitly, but rather determined from the number of "missing values". What exactly should be considered a missing value differs for each type T, which is why a TinyVectorTrait::Missing is defined for useful types. You can also define one yourself.
Definition at line 73 of file TinyVector.h.
typedef const T* PLearn::TinyVector< T, N, TTrait >::const_iterator |
Definition at line 82 of file TinyVector.h.
typedef const T* PLearn::TinyVector< T, N, TTrait >::const_pointer |
Definition at line 85 of file TinyVector.h.
typedef const T& PLearn::TinyVector< T, N, TTrait >::const_reference |
Definition at line 87 of file TinyVector.h.
typedef ptrdiff_t PLearn::TinyVector< T, N, TTrait >::difference_type |
Definition at line 79 of file TinyVector.h.
typedef T* PLearn::TinyVector< T, N, TTrait >::iterator |
Definition at line 81 of file TinyVector.h.
typedef T* PLearn::TinyVector< T, N, TTrait >::pointer |
Definition at line 84 of file TinyVector.h.
typedef T& PLearn::TinyVector< T, N, TTrait >::reference |
Definition at line 86 of file TinyVector.h.
typedef size_t PLearn::TinyVector< T, N, TTrait >::size_type |
Definition at line 78 of file TinyVector.h.
typedef T PLearn::TinyVector< T, N, TTrait >::value_type |
Typedefs.
Definition at line 77 of file TinyVector.h.
PLearn::TinyVector< T, N, TTrait >::TinyVector | ( | ) | [inline] |
PLearn::TinyVector< T, N, TTrait >::TinyVector | ( | size_type | n, |
const T & | val = T() |
||
) | [inline, explicit] |
void PLearn::TinyVector< T, N, TTrait >::assign | ( | In | first, |
In | last | ||
) | [inline] |
void PLearn::TinyVector< T, N, TTrait >::assign | ( | size_type | n, |
const T & | val | ||
) | [inline] |
TinyVector< T, N, TTrait >::const_reference PLearn::TinyVector< T, N, TTrait >::at | ( | size_type | n | ) | const |
TinyVector< T, N, TTrait >::reference PLearn::TinyVector< T, N, TTrait >::at | ( | size_type | n | ) |
TinyVector< T, N, TTrait >::reference PLearn::TinyVector< T, N, TTrait >::back | ( | ) | [inline] |
TinyVector< T, N, TTrait >::const_reference PLearn::TinyVector< T, N, TTrait >::back | ( | ) | const [inline] |
TinyVector< T, N, TTrait >::const_iterator PLearn::TinyVector< T, N, TTrait >::begin | ( | ) | const [inline] |
This is always correct, even for zero-size vectors
Definition at line 291 of file TinyVector.h.
{ return &arr[0]; }
TinyVector< T, N, TTrait >::iterator PLearn::TinyVector< T, N, TTrait >::begin | ( | ) | [inline] |
Iterators.
This is always correct, even for zero-size vectors
Definition at line 283 of file TinyVector.h.
Referenced by PLearn::operator==(), and PLearn::operator>>().
{ return &arr[0]; }
TinyVector PLearn::TinyVector< T, N, TTrait >::copy | ( | ) | const [inline] |
For compatibility with TVec, copy() simply returns a copy of ourselves.
Definition at line 161 of file TinyVector.h.
{ return *this; }
bool PLearn::TinyVector< T, N, TTrait >::empty | ( | ) | const [inline] |
Definition at line 142 of file TinyVector.h.
Referenced by PLearn::TTensor< T >::DEPRECATEDsubTensor(), and PLearn::TTensor< T >::subTensor().
{ return size() == 0; }
TinyVector< T, N, TTrait >::const_iterator PLearn::TinyVector< T, N, TTrait >::end | ( | ) | const [inline] |
Definition at line 306 of file TinyVector.h.
TinyVector< T, N, TTrait >::iterator PLearn::TinyVector< T, N, TTrait >::end | ( | ) | [inline] |
Definition at line 299 of file TinyVector.h.
Referenced by PLearn::operator==().
void PLearn::TinyVector< T, N, TTrait >::fill | ( | const T & | value | ) |
TinyVector< T, N, TTrait >::reference PLearn::TinyVector< T, N, TTrait >::front | ( | ) | [inline] |
TinyVector< T, N, TTrait >::const_reference PLearn::TinyVector< T, N, TTrait >::front | ( | ) | const [inline] |
size_type PLearn::TinyVector< T, N, TTrait >::max_size | ( | ) | [inline] |
Definition at line 145 of file TinyVector.h.
{ return N; }
TinyVector< T, N, TTrait >::reference PLearn::TinyVector< T, N, TTrait >::operator[] | ( | size_type | n | ) | [inline] |
TinyVector< T, N, TTrait >::const_reference PLearn::TinyVector< T, N, TTrait >::operator[] | ( | size_type | n | ) | const [inline] |
void PLearn::TinyVector< T, N, TTrait >::pop_back | ( | ) |
void PLearn::TinyVector< T, N, TTrait >::push_back | ( | const T & | x | ) |
Stack operations.
add to end
Definition at line 432 of file TinyVector.h.
Referenced by PLearn::TTensor< T >::DEPRECATEDsubTensor(), PLearn::TTensor< T >::operator[](), PLearn::TTensor< T >::selectDimensions(), and PLearn::TTensor< T >::subTensor().
{ size_type s = size(); if (s >= N) PLERROR("%s: out-of-range.",typeid(*this).name()); arr[s] = x; }
void PLearn::TinyVector< T, N, TTrait >::reserve | ( | size_type | n | ) |
void PLearn::TinyVector< T, N, TTrait >::resize | ( | size_type | sz, |
const T & | val = T() |
||
) |
added elts init by val
Definition at line 466 of file TinyVector.h.
Referenced by PLearn::TTensor< T >::lastElementPos(), PLearn::operator>>(), and PLearn::TTensor< T >::resize().
{ if (sz > max_size()) PLERROR("%s: out-of-range.",typeid(*this).name()); size_type s = size(); while (s < sz) arr[s++] = val; while (sz < N) arr[sz++] = TTrait::Missing; }
TinyVector< T, N, TTrait >::size_type PLearn::TinyVector< T, N, TTrait >::size | ( | ) | const |
(list operations are NOT provided at the moment)
Size and capacity operations number of elements
Definition at line 456 of file TinyVector.h.
References N.
Referenced by PLearn::TTensor< T >::resize(), and PLearn::TTensor< T >::selectDimensions().
{ difference_type p = N-1; while (p >= 0 && arr[p] == static_cast<T>(TTrait::Missing)) p--; return p+1; }
void PLearn::TinyVector< T, N, TTrait >::swap | ( | TinyVector< T, N, TTrait > & | other | ) |
Swap this with the argument.
< if necessary for swap; otherwise uses Koenig lookup
Definition at line 490 of file TinyVector.h.
References PLearn::TinyVector< T, N, TTrait >::arr, i, N, and PLearn::swap().
T PLearn::TinyVector< T, N, TTrait >::arr[N] [private] |
Definition at line 164 of file TinyVector.h.
Referenced by PLearn::TinyVector< T, N, TTrait >::swap().