Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
prevector< N, T, Size, Diff > Class Template Reference

Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without heap allocation). More...

#include <prevector.h>

Inheritance diagram for prevector< N, T, Size, Diff >:
[legend]
Collaboration diagram for prevector< N, T, Size, Diff >:
[legend]

Classes

class  const_iterator
 
class  const_reverse_iterator
 
union  direct_or_indirect
 
class  iterator
 
class  reverse_iterator
 

Public Types

typedef Size size_type
 
typedef Diff difference_type
 
typedef T value_type
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 

Public Member Functions

void assign (size_type n, const T &val)
 
template<std::input_iterator InputIterator>
void assign (InputIterator first, InputIterator last)
 
 prevector ()=default
 
 prevector (size_type n)
 
 prevector (size_type n, const T &val)
 
template<std::input_iterator InputIterator>
 prevector (InputIterator first, InputIterator last)
 
 prevector (const prevector< N, T, Size, Diff > &other)
 
 prevector (prevector< N, T, Size, Diff > &&other) noexcept
 
prevectoroperator= (const prevector< N, T, Size, Diff > &other)
 
prevectoroperator= (prevector< N, T, Size, Diff > &&other) noexcept
 
size_type size () const
 
bool empty () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_t capacity () const
 
Toperator[] (size_type pos)
 
const Toperator[] (size_type pos) const
 
void resize (size_type new_size)
 
void reserve (size_type new_capacity)
 
void shrink_to_fit ()
 
void clear ()
 
iterator insert (iterator pos, const T &value)
 
void insert (iterator pos, size_type count, const T &value)
 
template<std::input_iterator InputIterator>
void insert (iterator pos, InputIterator first, InputIterator last)
 
void resize_uninitialized (size_type new_size)
 
iterator erase (iterator pos)
 
iterator erase (iterator first, iterator last)
 
template<typename... Args>
void emplace_back (Args &&... args)
 
void push_back (const T &value)
 
void pop_back ()
 
Tfront ()
 
const Tfront () const
 
Tback ()
 
const Tback () const
 
void swap (prevector< N, T, Size, Diff > &other) noexcept
 
 ~prevector ()
 
bool operator== (const prevector< N, T, Size, Diff > &other) const
 
bool operator!= (const prevector< N, T, Size, Diff > &other) const
 
bool operator< (const prevector< N, T, Size, Diff > &other) const
 
size_t allocated_memory () const
 
value_typedata ()
 
const value_typedata () const
 

Private Member Functions

Tdirect_ptr (difference_type pos)
 
const Tdirect_ptr (difference_type pos) const
 
Tindirect_ptr (difference_type pos)
 
const Tindirect_ptr (difference_type pos) const
 
bool is_direct () const
 
void change_capacity (size_type new_capacity)
 
Titem_ptr (difference_type pos)
 
const Titem_ptr (difference_type pos) const
 
void fill (T *dst, ptrdiff_t count, const T &value=T{})
 
template<std::input_iterator InputIterator>
void fill (T *dst, InputIterator first, InputIterator last)
 

Private Attributes

direct_or_indirect _union = {}
 
size_type _size = 0
 

Detailed Description

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
class prevector< N, T, Size, Diff >

Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without heap allocation).

The types Size and Diff are used to store element counts, and can be any unsigned + signed type.

Storage layout is either:

The data type T must be movable by memmove/realloc(). Once we switch to C++, move constructors can be used instead.

Definition at line 37 of file prevector.h.

Member Typedef Documentation

◆ const_pointer

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef const value_type* prevector< N, T, Size, Diff >::const_pointer

Definition at line 47 of file prevector.h.

◆ const_reference

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef const value_type& prevector< N, T, Size, Diff >::const_reference

Definition at line 45 of file prevector.h.

◆ difference_type

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef Diff prevector< N, T, Size, Diff >::difference_type

Definition at line 42 of file prevector.h.

◆ pointer

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef value_type* prevector< N, T, Size, Diff >::pointer

Definition at line 46 of file prevector.h.

◆ reference

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef value_type& prevector< N, T, Size, Diff >::reference

Definition at line 44 of file prevector.h.

◆ size_type

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef Size prevector< N, T, Size, Diff >::size_type

Definition at line 41 of file prevector.h.

◆ value_type

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
typedef T prevector< N, T, Size, Diff >::value_type

Definition at line 43 of file prevector.h.

Constructor & Destructor Documentation

◆ prevector() [1/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( )
default

◆ prevector() [2/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( size_type  n)
inlineexplicit

Definition at line 245 of file prevector.h.

Here is the call graph for this function:

◆ prevector() [3/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( size_type  n,
const T val 
)
inlineexplicit

Definition at line 249 of file prevector.h.

Here is the call graph for this function:

◆ prevector() [4/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
template<std::input_iterator InputIterator>
prevector< N, T, Size, Diff >::prevector ( InputIterator  first,
InputIterator  last 
)
inline

Definition at line 256 of file prevector.h.

Here is the call graph for this function:

◆ prevector() [5/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( const prevector< N, T, Size, Diff > &  other)
inline

Definition at line 263 of file prevector.h.

Here is the call graph for this function:

◆ prevector() [6/6]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( prevector< N, T, Size, Diff > &&  other)
inlinenoexcept

Definition at line 270 of file prevector.h.

◆ ~prevector()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::~prevector ( )
inline

Definition at line 474 of file prevector.h.

Here is the call graph for this function:

Member Function Documentation

◆ allocated_memory()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
size_t prevector< N, T, Size, Diff >::allocated_memory ( ) const
inline

Definition at line 525 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
template<std::input_iterator InputIterator>
void prevector< N, T, Size, Diff >::assign ( InputIterator  first,
InputIterator  last 
)
inline

Definition at line 233 of file prevector.h.

Here is the call graph for this function:

◆ assign() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::assign ( size_type  n,
const T val 
)
inline

Definition at line 223 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ back() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T & prevector< N, T, Size, Diff >::back ( )
inline

Definition at line 460 of file prevector.h.

Here is the call graph for this function:

◆ back() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T & prevector< N, T, Size, Diff >::back ( ) const
inline

Definition at line 464 of file prevector.h.

Here is the call graph for this function:

◆ begin() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::begin ( )
inline

Definition at line 302 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const_iterator prevector< N, T, Size, Diff >::begin ( ) const
inline

Definition at line 303 of file prevector.h.

Here is the call graph for this function:

◆ capacity()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
size_t prevector< N, T, Size, Diff >::capacity ( ) const
inline

Definition at line 312 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_capacity()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::change_capacity ( size_type  new_capacity)
inlineprivate

Definition at line 175 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::clear ( )
inline

Definition at line 355 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
value_type * prevector< N, T, Size, Diff >::data ( )
inline

Definition at line 533 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const value_type * prevector< N, T, Size, Diff >::data ( ) const
inline

Definition at line 537 of file prevector.h.

Here is the call graph for this function:

◆ direct_ptr() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T * prevector< N, T, Size, Diff >::direct_ptr ( difference_type  pos)
inlineprivate

Definition at line 169 of file prevector.h.

Here is the caller graph for this function:

◆ direct_ptr() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T * prevector< N, T, Size, Diff >::direct_ptr ( difference_type  pos) const
inlineprivate

Definition at line 170 of file prevector.h.

◆ emplace_back()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
template<typename... Args>
void prevector< N, T, Size, Diff >::emplace_back ( Args &&...  args)
inline

Definition at line 435 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::empty ( ) const
inline

Definition at line 298 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::end ( )
inline

Definition at line 304 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const_iterator prevector< N, T, Size, Diff >::end ( ) const
inline

Definition at line 305 of file prevector.h.

Here is the call graph for this function:

◆ erase() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::erase ( iterator  first,
iterator  last 
)
inline

Definition at line 420 of file prevector.h.

Here is the call graph for this function:

◆ erase() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::erase ( iterator  pos)
inline

Definition at line 416 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
template<std::input_iterator InputIterator>
void prevector< N, T, Size, Diff >::fill ( T dst,
InputIterator  first,
InputIterator  last 
)
inlineprivate

Definition at line 214 of file prevector.h.

◆ fill() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::fill ( T dst,
ptrdiff_t  count,
const T value = T{} 
)
inlineprivate

Definition at line 209 of file prevector.h.

Here is the caller graph for this function:

◆ front() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T & prevector< N, T, Size, Diff >::front ( )
inline

Definition at line 452 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ front() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T & prevector< N, T, Size, Diff >::front ( ) const
inline

Definition at line 456 of file prevector.h.

Here is the call graph for this function:

◆ indirect_ptr() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T * prevector< N, T, Size, Diff >::indirect_ptr ( difference_type  pos)
inlineprivate

Definition at line 171 of file prevector.h.

Here is the caller graph for this function:

◆ indirect_ptr() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T * prevector< N, T, Size, Diff >::indirect_ptr ( difference_type  pos) const
inlineprivate

Definition at line 172 of file prevector.h.

◆ insert() [1/3]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::insert ( iterator  pos,
const T value 
)
inline

Definition at line 359 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [2/3]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
template<std::input_iterator InputIterator>
void prevector< N, T, Size, Diff >::insert ( iterator  pos,
InputIterator  first,
InputIterator  last 
)
inline

Definition at line 387 of file prevector.h.

Here is the call graph for this function:

◆ insert() [3/3]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::insert ( iterator  pos,
size_type  count,
const T value 
)
inline

Definition at line 373 of file prevector.h.

Here is the call graph for this function:

◆ is_direct()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::is_direct ( ) const
inlineprivate

Definition at line 173 of file prevector.h.

Here is the caller graph for this function:

◆ item_ptr() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T * prevector< N, T, Size, Diff >::item_ptr ( difference_type  pos)
inlineprivate

Definition at line 206 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ item_ptr() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T * prevector< N, T, Size, Diff >::item_ptr ( difference_type  pos) const
inlineprivate

Definition at line 207 of file prevector.h.

Here is the call graph for this function:

◆ operator!=()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator!= ( const prevector< N, T, Size, Diff > &  other) const
inline

Definition at line 498 of file prevector.h.

◆ operator<()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator< ( const prevector< N, T, Size, Diff > &  other) const
inline

Definition at line 502 of file prevector.h.

Here is the call graph for this function:

◆ operator=() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector & prevector< N, T, Size, Diff >::operator= ( const prevector< N, T, Size, Diff > &  other)
inline

Definition at line 276 of file prevector.h.

Here is the call graph for this function:

◆ operator=() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
prevector & prevector< N, T, Size, Diff >::operator= ( prevector< N, T, Size, Diff > &&  other)
inlinenoexcept

Definition at line 284 of file prevector.h.

Here is the call graph for this function:

◆ operator==()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator== ( const prevector< N, T, Size, Diff > &  other) const
inline

Definition at line 481 of file prevector.h.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
T & prevector< N, T, Size, Diff >::operator[] ( size_type  pos)
inline

Definition at line 320 of file prevector.h.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const T & prevector< N, T, Size, Diff >::operator[] ( size_type  pos) const
inline

Definition at line 324 of file prevector.h.

Here is the call graph for this function:

◆ pop_back()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::pop_back ( )
inline

Definition at line 448 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::push_back ( const T value)
inline

Definition at line 444 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rbegin() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
reverse_iterator prevector< N, T, Size, Diff >::rbegin ( )
inline

Definition at line 307 of file prevector.h.

Here is the call graph for this function:

◆ rbegin() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const_reverse_iterator prevector< N, T, Size, Diff >::rbegin ( ) const
inline

Definition at line 308 of file prevector.h.

Here is the call graph for this function:

◆ rend() [1/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
reverse_iterator prevector< N, T, Size, Diff >::rend ( )
inline

Definition at line 309 of file prevector.h.

Here is the call graph for this function:

◆ rend() [2/2]

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
const_reverse_iterator prevector< N, T, Size, Diff >::rend ( ) const
inline

Definition at line 310 of file prevector.h.

Here is the call graph for this function:

◆ reserve()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::reserve ( size_type  new_capacity)
inline

Definition at line 345 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::resize ( size_type  new_size)
inline

Definition at line 328 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize_uninitialized()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::resize_uninitialized ( size_type  new_size)
inline

Definition at line 401 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shrink_to_fit()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::shrink_to_fit ( )
inline

Definition at line 351 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
size_type prevector< N, T, Size, Diff >::size ( ) const
inline

Definition at line 294 of file prevector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::swap ( prevector< N, T, Size, Diff > &  other)
inlinenoexcept

Definition at line 468 of file prevector.h.

Here is the caller graph for this function:

Member Data Documentation

◆ _size

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
size_type prevector< N, T, Size, Diff >::_size = 0
private

Definition at line 164 of file prevector.h.

◆ _union

template<unsigned int N, typename T , typename Size = uint32_t, typename Diff = int32_t>
direct_or_indirect prevector< N, T, Size, Diff >::_union = {}
private

Definition at line 163 of file prevector.h.


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