![]() |
|
This is a small-vector class with local storage optimization, the local storage can be specified via a template parameter, and expresses the number of entries the container can store locally. More...
#include <smallVector.h>
Inherits TfSmallVectorBase.
Public Types | |
Relevant Typedefs. | |
XXX: Functionality currently missing, and which we would like to add as needed:
| |
typedef T | value_type |
typedef T & | reference |
typedef const T & | const_reference |
Public Member Functions | |
reference | front () |
Returns the first element in the vector. | |
const_reference | front () const |
Returns the first element in the vector. | |
reference | back () |
Returns the last element in the vector. | |
const_reference | back () const |
Returns the last elements in the vector. | |
reference | operator[] (size_type i) |
Access the specified element. | |
const_reference | operator[] (size_type i) const |
Access the specified element. | |
value_type * | data () |
Direct access to the underlying array. | |
const value_type * | data () const |
Direct access to the underlying array. | |
bool | operator== (const TfSmallVector &rhs) const |
Lexicographically compares the elements in the vectors for equality. | |
bool | operator!= (const TfSmallVector &rhs) const |
Lexicographically compares the elements in the vectors for inequality. | |
Returns an iterator to the beginning of the vector. | |
iterator | begin () |
const_iterator | begin () const |
const_iterator | cbegin () const |
Returns an iterator to the end of the vector. | |
iterator | end () |
const_iterator | end () const |
const_iterator | cend () const |
Returns a reverse iterator to the beginning of the vector. | |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | crbegin () const |
Returns a reverse iterator to the end of the vector. | |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
const_reverse_iterator | crend () const |
Iterator Support. | |
}@ | |
enum | DefaultInitTag { DefaultInit } |
Construct a vector holding n default-initialized elements. More... | |
using | iterator = T * |
using | const_iterator = const T * |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
TfSmallVector () | |
}@ | |
TfSmallVector (size_type n) | |
Construct a vector holding n value-initialized elements. | |
TfSmallVector (size_type n, const value_type &v) | |
Construct a vector holding n copies of v . | |
TfSmallVector (size_type n, DefaultInitTag) | |
TfSmallVector (const TfSmallVector &rhs) | |
Copy constructor. | |
TfSmallVector (TfSmallVector &&rhs) | |
Move constructor. | |
TfSmallVector (std::initializer_list< T > values) | |
Construct a new vector from initializer list. | |
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>> | |
TfSmallVector (ForwardIterator first, ForwardIterator last) | |
Creates a new vector containing copies of the data between first and last . | |
~TfSmallVector () | |
Destructor. | |
TfSmallVector & | operator= (const TfSmallVector &rhs) |
Assignment operator. | |
TfSmallVector & | operator= (TfSmallVector &&rhs) |
Move assignment operator. | |
TfSmallVector & | operator= (std::initializer_list< T > ilist) |
Replace existing contents with the contents of ilist . | |
void | swap (TfSmallVector &rhs) |
Swap two vector instances. | |
iterator | insert (const_iterator it, value_type &&v) |
Insert an rvalue-reference entry at the given iterator position. | |
iterator | insert (const_iterator it, const value_type &v) |
Insert an entry at the given iterator. | |
iterator | erase (const_iterator it) |
Erase an entry at the given iterator. | |
iterator | erase (const_iterator it, const_iterator last) |
Erase entries between [ first , last ) from the vector. | |
void | reserve (size_type newCapacity) |
Reserve storage for newCapacity entries. | |
void | resize (size_type newSize, const value_type &v=value_type()) |
Resize the vector to newSize and insert copies of \v. | |
void | clear () |
Clear the entries in the vector. | |
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>> | |
void | assign (ForwardIterator first, ForwardIterator last) |
Clears any previously held entries, and copies entries between [ first , last ) to this vector. | |
void | assign (std::initializer_list< T > ilist) |
Replace existing contents with the contents of ilist . | |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
Emplace an entry at the back of the vector. | |
void | push_back (const value_type &v) |
Copy an entry to the back of the vector,. | |
void | push_back (value_type &&v) |
Move an entry to the back of the vector. | |
template<typename ForwardIterator > | |
void | insert (iterator pos, ForwardIterator first, ForwardIterator last) |
Copy the range denoted by [first , last ) into this vector before pos . | |
void | insert (iterator pos, std::initializer_list< T > ilist) |
Insert elements from ilist starting at position pos . | |
void | pop_back () |
Remove the entry at the back of the vector. | |
size_type | size () const |
Returns the current size of the vector. | |
bool | empty () const |
Returns true if this vector is empty. | |
size_type | capacity () const |
Returns the current capacity of this vector. | |
static constexpr size_type | max_size () |
Returns the maximum size of this vector. | |
static constexpr size_type | internal_capacity () |
Returns the local storage capacity. | |
This is a small-vector class with local storage optimization, the local storage can be specified via a template parameter, and expresses the number of entries the container can store locally.
In addition to the local storage optimization, this vector is also optimized for storing a smaller number of entries on the heap: It features a reduced memory footprint (minimum 16 bytes) by limiting max_size() to 2^32, which should still be more than enough for most use cases where a small-vector is advantageous.
TfSmallVector mimics the std::vector API, and can thus be easily used as a drop-in replacement where appropriate. Note, however, that not all the methods on std::vector are implemented here, and that TfSmallVector may have methods in addition to those that you would find on std::vector.
Note that a TfSmallVector that has grown beyond its local storage, will NOT move its entries back into the local storage once it shrinks back to N.
Definition at line 156 of file smallVector.h.
using const_iterator = const T* |
Definition at line 180 of file smallVector.h.
typedef const T& const_reference |
Definition at line 172 of file smallVector.h.
typedef std::reverse_iterator<const_iterator> const_reverse_iterator |
Definition at line 182 of file smallVector.h.
using iterator = T* |
Definition at line 179 of file smallVector.h.
typedef T& reference |
Definition at line 171 of file smallVector.h.
typedef std::reverse_iterator<iterator> reverse_iterator |
Definition at line 181 of file smallVector.h.
typedef T value_type |
Definition at line 170 of file smallVector.h.
enum DefaultInitTag |
Construct a vector holding n
default-initialized elements.
Definition at line 211 of file smallVector.h.
|
inline |
|
inlineexplicit |
Construct a vector holding n
value-initialized elements.
Definition at line 192 of file smallVector.h.
|
inline |
Construct a vector holding n
copies of v
.
Definition at line 203 of file smallVector.h.
|
inline |
Definition at line 212 of file smallVector.h.
|
inline |
Copy constructor.
Definition at line 223 of file smallVector.h.
|
inline |
Move constructor.
Definition at line 230 of file smallVector.h.
|
inline |
Construct a new vector from initializer list.
Definition at line 250 of file smallVector.h.
|
inline |
Creates a new vector containing copies of the data between first
and last
.
Definition at line 258 of file smallVector.h.
|
inline |
Destructor.
Definition at line 266 of file smallVector.h.
|
inline |
Clears any previously held entries, and copies entries between [ first
, last
) to this vector.
Definition at line 451 of file smallVector.h.
|
inline |
Replace existing contents with the contents of ilist
.
Definition at line 461 of file smallVector.h.
|
inline |
Returns the last element in the vector.
Definition at line 711 of file smallVector.h.
|
inline |
Returns the last elements in the vector.
Definition at line 717 of file smallVector.h.
|
inline |
Definition at line 632 of file smallVector.h.
|
inline |
Definition at line 636 of file smallVector.h.
|
inline |
Returns the current capacity of this vector.
Note that if the returned value is <= N, it does NOT mean the storage is local. A vector that has previously grown beyond its local storage, will not move entries back to the local storage once it shrinks to N.
Definition at line 617 of file smallVector.h.
|
inline |
Definition at line 640 of file smallVector.h.
|
inline |
Definition at line 657 of file smallVector.h.
|
inline |
Clear the entries in the vector.
Does not let go of the underpinning storage.
Definition at line 441 of file smallVector.h.
|
inline |
Definition at line 674 of file smallVector.h.
|
inline |
Definition at line 691 of file smallVector.h.
|
inline |
Direct access to the underlying array.
Definition at line 735 of file smallVector.h.
|
inline |
Direct access to the underlying array.
Definition at line 741 of file smallVector.h.
|
inline |
Emplace an entry at the back of the vector.
Definition at line 468 of file smallVector.h.
|
inline |
Returns true
if this vector is empty.
Definition at line 608 of file smallVector.h.
|
inline |
Definition at line 649 of file smallVector.h.
|
inline |
Definition at line 653 of file smallVector.h.
|
inline |
Erase an entry at the given iterator.
Definition at line 375 of file smallVector.h.
|
inline |
Erase entries between [ first
, last
) from the vector.
Definition at line 381 of file smallVector.h.
|
inline |
Returns the first element in the vector.
Definition at line 699 of file smallVector.h.
|
inline |
Returns the first element in the vector.
Definition at line 705 of file smallVector.h.
|
inline |
Insert an entry at the given iterator.
Definition at line 369 of file smallVector.h.
|
inline |
Insert an rvalue-reference entry at the given iterator position.
Definition at line 363 of file smallVector.h.
|
inline |
Copy the range denoted by [first
, last
) into this vector before pos
.
Definition at line 492 of file smallVector.h.
|
inline |
Insert elements from ilist
starting at position pos
.
Definition at line 583 of file smallVector.h.
|
inlinestaticconstexpr |
Returns the local storage capacity.
The vector uses its local storage if capacity() <= internal_capacity(). This method mimics the boost::container::small_vector interface.
Definition at line 625 of file smallVector.h.
|
inlinestaticconstexpr |
Returns the maximum size of this vector.
Definition at line 602 of file smallVector.h.
|
inline |
Lexicographically compares the elements in the vectors for inequality.
Definition at line 753 of file smallVector.h.
|
inline |
Assignment operator.
Definition at line 273 of file smallVector.h.
|
inline |
Replace existing contents with the contents of ilist
.
Definition at line 291 of file smallVector.h.
|
inline |
Move assignment operator.
Definition at line 282 of file smallVector.h.
|
inline |
Lexicographically compares the elements in the vectors for equality.
Definition at line 747 of file smallVector.h.
|
inline |
Access the specified element.
Definition at line 723 of file smallVector.h.
|
inline |
Access the specified element.
Definition at line 729 of file smallVector.h.
|
inline |
Remove the entry at the back of the vector.
Definition at line 589 of file smallVector.h.
|
inline |
Copy an entry to the back of the vector,.
Definition at line 478 of file smallVector.h.
|
inline |
Move an entry to the back of the vector.
Definition at line 484 of file smallVector.h.
|
inline |
Definition at line 666 of file smallVector.h.
|
inline |
Definition at line 670 of file smallVector.h.
|
inline |
Definition at line 683 of file smallVector.h.
|
inline |
Definition at line 687 of file smallVector.h.
|
inline |
Reserve storage for newCapacity
entries.
Definition at line 410 of file smallVector.h.
|
inline |
Resize the vector to newSize
and insert copies of \v.
Definition at line 421 of file smallVector.h.
|
inline |
Returns the current size of the vector.
Definition at line 596 of file smallVector.h.
|
inline |
Swap two vector instances.
Definition at line 298 of file smallVector.h.