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

#include <smallVector.h>

+ Inheritance diagram for TfSmallVector< T, N >:

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 Treference
 
typedef const Tconst_reference
 
- Public Types inherited from TfSmallVectorBase
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

reference front ()
 
const_reference front () const
 
reference back ()
 
const_reference back () const
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
value_typedata ()
 
const value_typedata () const
 
bool operator== (const TfSmallVector &rhs) const
 
bool operator!= (const TfSmallVector &rhs) const
 
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 }
 
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 ()
 }@ More...
 
 TfSmallVector (size_type n)
 
 TfSmallVector (size_type n, const value_type &v)
 
 TfSmallVector (size_type n, DefaultInitTag)
 
 TfSmallVector (const TfSmallVector &rhs)
 
 TfSmallVector (TfSmallVector &&rhs)
 
 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)
 
 ~TfSmallVector ()
 
TfSmallVectoroperator= (const TfSmallVector &rhs)
 
TfSmallVectoroperator= (TfSmallVector &&rhs)
 
TfSmallVectoroperator= (std::initializer_list< T > ilist)
 
void swap (TfSmallVector &rhs)
 
iterator insert (const_iterator it, value_type &&v)
 
iterator insert (const_iterator it, const value_type &v)
 
iterator erase (const_iterator it)
 
iterator erase (const_iterator it, const_iterator last)
 
void reserve (size_type newCapacity)
 
void resize (size_type newSize, const value_type &v=value_type())
 
void clear ()
 
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>>
void assign (ForwardIterator first, ForwardIterator last)
 
void assign (std::initializer_list< T > ilist)
 
template<typename... Args>
void emplace_back (Args &&...args)
 
void push_back (const value_type &v)
 
void push_back (value_type &&v)
 
template<typename ForwardIterator >
void insert (iterator pos, ForwardIterator first, ForwardIterator last)
 
void insert (iterator pos, std::initializer_list< T > ilist)
 
void pop_back ()
 
size_type size () const
 
bool empty () const
 
size_type capacity () const
 
static constexpr size_type max_size ()
 
static constexpr size_type internal_capacity ()
 

Additional Inherited Members

- Static Public Member Functions inherited from TfSmallVectorBase
template<typename U >
static constexpr size_type ComputeSerendipitousLocalCapacity ()
 
- Protected Types inherited from TfSmallVectorBase
using _SizeMemberType = std::uint32_t
 
template<class ValueType , size_t NumLocal>
using _Data = _DataUnion< sizeof(ValueType), alignof(ValueType), NumLocal >
 
template<typename _ForwardIterator >
using _EnableIfForwardIterator = std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< _ForwardIterator >::iterator_category, std::forward_iterator_tag > >
 
- Static Protected Member Functions inherited from TfSmallVectorBase
template<typename Iterator >
static Iterator _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 156 of file smallVector.h.

Member Typedef Documentation

template<typename T, uint32_t N>
using TfSmallVector< T, N >::const_iterator = const T*

Construct a vector holding n default-initialized elements.

Definition at line 180 of file smallVector.h.

template<typename T, uint32_t N>
typedef const T& TfSmallVector< T, N >::const_reference

Definition at line 172 of file smallVector.h.

template<typename T, uint32_t N>
typedef std::reverse_iterator<const_iterator> TfSmallVector< T, N >::const_reverse_iterator

Construct a vector holding n default-initialized elements.

Definition at line 182 of file smallVector.h.

template<typename T, uint32_t N>
using TfSmallVector< T, N >::iterator = T*

Construct a vector holding n default-initialized elements.

Definition at line 179 of file smallVector.h.

template<typename T, uint32_t N>
typedef T& TfSmallVector< T, N >::reference

Definition at line 171 of file smallVector.h.

template<typename T, uint32_t N>
typedef std::reverse_iterator<iterator> TfSmallVector< T, N >::reverse_iterator

Construct a vector holding n default-initialized elements.

Definition at line 181 of file smallVector.h.

template<typename T, uint32_t N>
typedef T TfSmallVector< T, N >::value_type

Definition at line 170 of file smallVector.h.

Member Enumeration Documentation

template<typename T, uint32_t N>
enum TfSmallVector::DefaultInitTag

Construct a vector holding n default-initialized elements.

Enumerator
DefaultInit 

Definition at line 211 of file smallVector.h.

Constructor & Destructor Documentation

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( )
inline

}@

Default constructor.

Definition at line 188 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( size_type  n)
inlineexplicit

Construct a vector holding n value-initialized elements.

Definition at line 192 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( size_type  n,
const value_type v 
)
inline

Construct a vector holding n copies of v.

Definition at line 203 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( size_type  n,
DefaultInitTag   
)
inline

Construct a vector holding n default-initialized elements.

Definition at line 212 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( const TfSmallVector< T, N > &  rhs)
inline

Copy constructor.

Definition at line 223 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( TfSmallVector< T, N > &&  rhs)
inline

Move constructor.

Definition at line 230 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::TfSmallVector ( std::initializer_list< T values)
inline

Construct a new vector from initializer list.

Definition at line 250 of file smallVector.h.

template<typename T, uint32_t N>
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>>
TfSmallVector< T, N >::TfSmallVector ( ForwardIterator  first,
ForwardIterator  last 
)
inline

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

Definition at line 258 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector< T, N >::~TfSmallVector ( )
inline

Destructor.

Definition at line 266 of file smallVector.h.

Member Function Documentation

template<typename T, uint32_t N>
template<typename ForwardIterator , typename = _EnableIfForwardIterator<ForwardIterator>>
void TfSmallVector< T, N >::assign ( ForwardIterator  first,
ForwardIterator  last 
)
inline

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

Definition at line 451 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::assign ( std::initializer_list< T ilist)
inline

Replace existing contents with the contents of ilist.

Definition at line 461 of file smallVector.h.

template<typename T, uint32_t N>
reference TfSmallVector< T, N >::back ( void  )
inline

Returns the last element in the vector.

Definition at line 711 of file smallVector.h.

template<typename T, uint32_t N>
const_reference TfSmallVector< T, N >::back ( void  ) const
inline

Returns the last elements in the vector.

Definition at line 717 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::begin ( void  )
inline

Definition at line 632 of file smallVector.h.

template<typename T, uint32_t N>
const_iterator TfSmallVector< T, N >::begin ( void  ) const
inline

Definition at line 636 of file smallVector.h.

template<typename T, uint32_t N>
size_type TfSmallVector< T, N >::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 617 of file smallVector.h.

template<typename T, uint32_t N>
const_iterator TfSmallVector< T, N >::cbegin ( ) const
inline

Definition at line 640 of file smallVector.h.

template<typename T, uint32_t N>
const_iterator TfSmallVector< T, N >::cend ( ) const
inline

Definition at line 657 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::clear ( )
inline

Clear the entries in the vector. Does not let go of the underpinning storage.

Definition at line 441 of file smallVector.h.

template<typename T, uint32_t N>
const_reverse_iterator TfSmallVector< T, N >::crbegin ( ) const
inline

Definition at line 674 of file smallVector.h.

template<typename T, uint32_t N>
const_reverse_iterator TfSmallVector< T, N >::crend ( ) const
inline

Definition at line 691 of file smallVector.h.

template<typename T, uint32_t N>
value_type* TfSmallVector< T, N >::data ( )
inline

Direct access to the underlying array.

Definition at line 735 of file smallVector.h.

template<typename T, uint32_t N>
const value_type* TfSmallVector< T, N >::data ( ) const
inline

Direct access to the underlying array.

Definition at line 741 of file smallVector.h.

template<typename T, uint32_t N>
template<typename... Args>
void TfSmallVector< T, N >::emplace_back ( Args &&...  args)
inline

Emplace an entry at the back of the vector.

Definition at line 468 of file smallVector.h.

template<typename T, uint32_t N>
bool TfSmallVector< T, N >::empty ( void  ) const
inline

Returns true if this vector is empty.

Definition at line 608 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::end ( void  )
inline

Definition at line 649 of file smallVector.h.

template<typename T, uint32_t N>
const_iterator TfSmallVector< T, N >::end ( void  ) const
inline

Definition at line 653 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::erase ( const_iterator  it)
inline

Erase an entry at the given iterator.

Definition at line 375 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::erase ( const_iterator  it,
const_iterator  last 
)
inline

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

Definition at line 381 of file smallVector.h.

template<typename T, uint32_t N>
reference TfSmallVector< T, N >::front ( void  )
inline

Returns the first element in the vector.

Definition at line 699 of file smallVector.h.

template<typename T, uint32_t N>
const_reference TfSmallVector< T, N >::front ( void  ) const
inline

Returns the first element in the vector.

Definition at line 705 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::insert ( const_iterator  it,
value_type &&  v 
)
inline

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

Definition at line 363 of file smallVector.h.

template<typename T, uint32_t N>
iterator TfSmallVector< T, N >::insert ( const_iterator  it,
const value_type v 
)
inline

Insert an entry at the given iterator.

Definition at line 369 of file smallVector.h.

template<typename T, uint32_t N>
template<typename ForwardIterator >
void TfSmallVector< T, N >::insert ( iterator  pos,
ForwardIterator  first,
ForwardIterator  last 
)
inline

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

Definition at line 492 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::insert ( iterator  pos,
std::initializer_list< T ilist 
)
inline

Insert elements from ilist starting at position pos.

Definition at line 583 of file smallVector.h.

template<typename T, uint32_t N>
static constexpr size_type TfSmallVector< T, N >::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 625 of file smallVector.h.

template<typename T, uint32_t N>
static constexpr size_type TfSmallVector< T, N >::max_size ( void  )
inlinestatic

Returns the maximum size of this vector.

Definition at line 602 of file smallVector.h.

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

Lexicographically compares the elements in the vectors for inequality.

Definition at line 753 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector& TfSmallVector< T, N >::operator= ( const TfSmallVector< T, N > &  rhs)
inline

Assignment operator.

Definition at line 273 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector& TfSmallVector< T, N >::operator= ( TfSmallVector< T, N > &&  rhs)
inline

Move assignment operator.

Definition at line 282 of file smallVector.h.

template<typename T, uint32_t N>
TfSmallVector& TfSmallVector< T, N >::operator= ( std::initializer_list< T ilist)
inline

Replace existing contents with the contents of ilist.

Definition at line 291 of file smallVector.h.

template<typename T, uint32_t N>
bool TfSmallVector< T, N >::operator== ( const TfSmallVector< T, N > &  rhs) const
inline

Lexicographically compares the elements in the vectors for equality.

Definition at line 747 of file smallVector.h.

template<typename T, uint32_t N>
reference TfSmallVector< T, N >::operator[] ( size_type  i)
inline

Access the specified element.

Definition at line 723 of file smallVector.h.

template<typename T, uint32_t N>
const_reference TfSmallVector< T, N >::operator[] ( size_type  i) const
inline

Access the specified element.

Definition at line 729 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::pop_back ( )
inline

Remove the entry at the back of the vector.

Definition at line 589 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::push_back ( const value_type v)
inline

Copy an entry to the back of the vector,

Definition at line 478 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::push_back ( value_type &&  v)
inline

Move an entry to the back of the vector.

Definition at line 484 of file smallVector.h.

template<typename T, uint32_t N>
reverse_iterator TfSmallVector< T, N >::rbegin ( )
inline

Definition at line 666 of file smallVector.h.

template<typename T, uint32_t N>
const_reverse_iterator TfSmallVector< T, N >::rbegin ( ) const
inline

Definition at line 670 of file smallVector.h.

template<typename T, uint32_t N>
reverse_iterator TfSmallVector< T, N >::rend ( )
inline

Definition at line 683 of file smallVector.h.

template<typename T, uint32_t N>
const_reverse_iterator TfSmallVector< T, N >::rend ( ) const
inline

Definition at line 687 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::reserve ( size_type  newCapacity)
inline

Reserve storage for newCapacity entries.

Definition at line 410 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::resize ( size_type  newSize,
const value_type v = value_type() 
)
inline

Resize the vector to newSize and insert copies of .

Definition at line 421 of file smallVector.h.

template<typename T, uint32_t N>
size_type TfSmallVector< T, N >::size ( void  ) const
inline

Returns the current size of the vector.

Definition at line 596 of file smallVector.h.

template<typename T, uint32_t N>
void TfSmallVector< T, N >::swap ( TfSmallVector< T, N > &  rhs)
inline

Swap two vector instances.

Definition at line 298 of file smallVector.h.


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