All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfSmallVector< T, N > Class Template Reference

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

Inherits TfSmallVectorBase.

Public Types

Relevant Typedefs.

XXX: Functionality currently missing, and which we would like to add as needed:

  • emplace
  • shrink_to_fit
  • shrink_to_local / shrink_to_internal (or similar, free standing function)
typedef T value_type
 
typedef T & reference
 
typedef const T & const_reference
 
- Public Types inherited from TfSmallVectorBase
using size_type = std::uint32_t
 
using difference_type = std::int32_t
 

Public Member Functions

reference front ()
 Returns the first element in the vector. More...
 
const_reference front () const
 Returns the first element in the vector. More...
 
reference back ()
 Returns the last element in the vector. More...
 
const_reference back () const
 Returns the last elements in the vector. More...
 
reference operator[] (size_type i)
 Access the specified element. More...
 
const_reference operator[] (size_type i) const
 Access the specified element. More...
 
value_type * data ()
 Direct access to the underlying array. More...
 
const value_type * data () const
 Direct access to the underlying array. More...
 
bool operator== (const TfSmallVector &rhs) const
 Lexicographically compares the elements in the vectors for equality. More...
 
bool operator!= (const TfSmallVector &rhs) const
 Lexicographically compares the elements in the vectors for inequality. More...
 
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
 
template<typename _ForwardIterator >
using _EnableIfForwardIterator = typename std::enable_if< std::is_convertible< typename std::iterator_traits< _ForwardIterator >::iterator_category, std::forward_iterator_tag >::value >::type
 
 TfSmallVector ()
 }@ More...
 
 TfSmallVector (size_type n)
 Construct a vector holding n value-initialized elements. More...
 
 TfSmallVector (size_type n, const value_type &v)
 Construct a vector holding n copies of v. More...
 
 TfSmallVector (size_type n, DefaultInitTag)
 
 TfSmallVector (const TfSmallVector &rhs)
 Copy constructor. More...
 
 TfSmallVector (TfSmallVector &&rhs)
 Move constructor. More...
 
 TfSmallVector (std::initializer_list< T > values)
 Construct a new vector from initializer list. More...
 
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>>
 TfSmallVector (ForwardIterator first, ForwardIterator last)
 Creates a new vector containing copies of the data between first and last. More...
 
 ~TfSmallVector ()
 Destructor. More...
 
TfSmallVectoroperator= (const TfSmallVector &rhs)
 Assignment operator. More...
 
TfSmallVectoroperator= (TfSmallVector &&rhs)
 Move assignment operator. More...
 
TfSmallVectoroperator= (std::initializer_list< T > ilist)
 Replace existing contents with the contents of ilist. More...
 
void swap (TfSmallVector &rhs)
 Swap two vector instances. More...
 
iterator insert (const_iterator it, value_type &&v)
 Insert an rvalue-reference entry at the given iterator position. More...
 
iterator insert (const_iterator it, const value_type &v)
 Insert an entry at the given iterator. More...
 
iterator erase (const_iterator it)
 Erase an entry at the given iterator. More...
 
iterator erase (const_iterator it, const_iterator last)
 Erase entries between [ first, last ) from the vector. More...
 
void reserve (size_type newCapacity)
 Reserve storage for newCapacity entries. More...
 
void resize (size_type newSize, const value_type &v=value_type())
 Resize the vector to newSize and insert copies of . More...
 
void clear ()
 Clear the entries in the vector. More...
 
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. More...
 
void assign (std::initializer_list< T > ilist)
 Replace existing contents with the contents of ilist. More...
 
template<typename... Args>
void emplace_back (Args &&...args)
 Emplace an entry at the back of the vector. More...
 
void push_back (const value_type &v)
 Copy an entry to the back of the vector,. More...
 
void push_back (value_type &&v)
 Move an entry to the back of the vector. More...
 
template<typename ForwardIterator >
void insert (iterator pos, ForwardIterator first, ForwardIterator last)
 Copy the range denoted by [first, last) into this vector before pos. More...
 
void insert (iterator pos, std::initializer_list< T > ilist)
 Insert elements from ilist starting at position pos. More...
 
void pop_back ()
 Remove the entry at the back of the vector. More...
 
size_type size () const
 Returns the current size of the vector. More...
 
bool empty () const
 Returns true if this vector is empty. More...
 
size_type capacity () const
 Returns the current capacity of this vector. More...
 
static constexpr size_type max_size ()
 Returns the maximum size of this vector. More...
 
static constexpr size_type internal_capacity ()
 Returns the local storage capacity. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from TfSmallVectorBase
template<typename U >
static constexpr size_type ComputeSerendipitousLocalCapacity ()
 
- Static Protected Member Functions inherited from TfSmallVectorBase
template<typename Iterator >
static void _UninitializedMove (Iterator first, Iterator last, Iterator dest)
 
template<typename U >
static void _MoveConstruct (U *p, U *src)
 

Detailed Description

template<typename T, uint32_t N>
class TfSmallVector< T, N >

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 177 of file smallVector.h.

Member Enumeration Documentation

Construct a vector holding n default-initialized elements.

Definition at line 233 of file smallVector.h.

Constructor & Destructor Documentation

TfSmallVector ( )
inline

}@

Default constructor.

Definition at line 210 of file smallVector.h.

TfSmallVector ( size_type  n)
inlineexplicit

Construct a vector holding n value-initialized elements.

Definition at line 214 of file smallVector.h.

TfSmallVector ( size_type  n,
const value_type &  v 
)
inline

Construct a vector holding n copies of v.

Definition at line 225 of file smallVector.h.

TfSmallVector ( const TfSmallVector< T, N > &  rhs)
inline

Copy constructor.

Definition at line 245 of file smallVector.h.

TfSmallVector ( TfSmallVector< T, N > &&  rhs)
inline

Move constructor.

Definition at line 252 of file smallVector.h.

TfSmallVector ( std::initializer_list< T >  values)
inline

Construct a new vector from initializer list.

Definition at line 272 of file smallVector.h.

TfSmallVector ( ForwardIterator  first,
ForwardIterator  last 
)
inline

Creates a new vector containing copies of the data between first and last.

Definition at line 290 of file smallVector.h.

~TfSmallVector ( )
inline

Destructor.

Definition at line 298 of file smallVector.h.

Member Function Documentation

void assign ( ForwardIterator  first,
ForwardIterator  last 
)
inline

Clears any previously held entries, and copies entries between [ first, last ) to this vector.

Definition at line 484 of file smallVector.h.

void assign ( std::initializer_list< T >  ilist)
inline

Replace existing contents with the contents of ilist.

Definition at line 494 of file smallVector.h.

reference back ( )
inline

Returns the last element in the vector.

Definition at line 744 of file smallVector.h.

const_reference back ( ) const
inline

Returns the last elements in the vector.

Definition at line 750 of file smallVector.h.

size_type capacity ( ) const
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 650 of file smallVector.h.

void clear ( )
inline

Clear the entries in the vector.

Does not let go of the underpinning storage.

Definition at line 474 of file smallVector.h.

value_type* data ( )
inline

Direct access to the underlying array.

Definition at line 768 of file smallVector.h.

const value_type* data ( ) const
inline

Direct access to the underlying array.

Definition at line 774 of file smallVector.h.

void emplace_back ( Args &&...  args)
inline

Emplace an entry at the back of the vector.

Definition at line 501 of file smallVector.h.

bool empty ( ) const
inline

Returns true if this vector is empty.

Definition at line 641 of file smallVector.h.

iterator erase ( const_iterator  it)
inline

Erase an entry at the given iterator.

Definition at line 408 of file smallVector.h.

iterator erase ( const_iterator  it,
const_iterator  last 
)
inline

Erase entries between [ first, last ) from the vector.

Definition at line 414 of file smallVector.h.

reference front ( )
inline

Returns the first element in the vector.

Definition at line 732 of file smallVector.h.

const_reference front ( ) const
inline

Returns the first element in the vector.

Definition at line 738 of file smallVector.h.

iterator insert ( const_iterator  it,
value_type &&  v 
)
inline

Insert an rvalue-reference entry at the given iterator position.

Definition at line 396 of file smallVector.h.

iterator insert ( const_iterator  it,
const value_type &  v 
)
inline

Insert an entry at the given iterator.

Definition at line 402 of file smallVector.h.

void insert ( iterator  pos,
ForwardIterator  first,
ForwardIterator  last 
)
inline

Copy the range denoted by [first, last) into this vector before pos.

Definition at line 525 of file smallVector.h.

void insert ( iterator  pos,
std::initializer_list< T >  ilist 
)
inline

Insert elements from ilist starting at position pos.

Definition at line 616 of file smallVector.h.

static constexpr size_type internal_capacity ( )
inlinestatic

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 658 of file smallVector.h.

static constexpr size_type max_size ( )
inlinestatic

Returns the maximum size of this vector.

Definition at line 635 of file smallVector.h.

bool operator!= ( const TfSmallVector< T, N > &  rhs) const
inline

Lexicographically compares the elements in the vectors for inequality.

Definition at line 786 of file smallVector.h.

TfSmallVector& operator= ( const TfSmallVector< T, N > &  rhs)
inline

Assignment operator.

Definition at line 305 of file smallVector.h.

TfSmallVector& operator= ( TfSmallVector< T, N > &&  rhs)
inline

Move assignment operator.

Definition at line 314 of file smallVector.h.

TfSmallVector& operator= ( std::initializer_list< T >  ilist)
inline

Replace existing contents with the contents of ilist.

Definition at line 323 of file smallVector.h.

bool operator== ( const TfSmallVector< T, N > &  rhs) const
inline

Lexicographically compares the elements in the vectors for equality.

Definition at line 780 of file smallVector.h.

reference operator[] ( size_type  i)
inline

Access the specified element.

Definition at line 756 of file smallVector.h.

const_reference operator[] ( size_type  i) const
inline

Access the specified element.

Definition at line 762 of file smallVector.h.

void pop_back ( )
inline

Remove the entry at the back of the vector.

Definition at line 622 of file smallVector.h.

void push_back ( const value_type &  v)
inline

Copy an entry to the back of the vector,.

Definition at line 511 of file smallVector.h.

void push_back ( value_type &&  v)
inline

Move an entry to the back of the vector.

Definition at line 517 of file smallVector.h.

void reserve ( size_type  newCapacity)
inline

Reserve storage for newCapacity entries.

Definition at line 443 of file smallVector.h.

void resize ( size_type  newSize,
const value_type &  v = value_type() 
)
inline

Resize the vector to newSize and insert copies of .

Definition at line 454 of file smallVector.h.

size_type size ( ) const
inline

Returns the current size of the vector.

Definition at line 629 of file smallVector.h.

void swap ( TfSmallVector< T, N > &  rhs)
inline

Swap two vector instances.

Definition at line 330 of file smallVector.h.


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