xapian-core  2.0.0
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
Xapian::Vec< T, COW, UNIQUEPTR, typename > Class Template Reference

Suitable for "simple" type T. More...

#include <smallvector.h>

+ Inheritance diagram for Xapian::Vec< T, COW, UNIQUEPTR, typename >:

Classes

struct  Vec_to_copy
 

Public Types

typedef std::size_t size_type
 
typedef const T * const_iterator
 
typedef T * iterator
 

Public Member Functions

 Vec ()
 
 Vec (const Vec &)=delete
 
 Vec (const Vec_to_copy &o)
 
void operator= (const Vec &)=delete
 
void operator= (const Vec_to_copy &o)
 
template<bool ENABLE = !UNIQUEPTR>
auto copy () const -> typename std::enable_if_t< ENABLE, Vec_to_copy >
 
 Vec (Vec &&o) noexcept
 
void operator= (Vec &&o)
 
 Vec (size_type n)
 
 ~Vec ()
 
size_type size () const
 
size_type capacity () const
 
bool empty () const
 
void reserve (size_type n)
 
const_iterator cbegin () const
 
const_iterator cend () const
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
void push_back (T elt)
 
void pop_back ()
 
void clear ()
 
void erase (const_iterator it)
 
void erase (const_iterator b, const_iterator e)
 
void insert (const_iterator pos, const T &elt)
 
const T & operator[] (size_type idx) const
 
T & operator[] (size_type idx)
 
const T & front () const
 
const T & back () const
 
template<bool ENABLE = !UNIQUEPTR>
release_at (size_type idx)
 

Protected Member Functions

void do_free ()
 
void do_reserve (size_type n)
 
void do_cow ()
 
void do_copy_from (const Vec &o)
 
bool is_external () const noexcept
 Return true if storage is external to the object. More...
 

Private Attributes

std::size_t c = 0
 
union {
   T   v [INTERNAL_CAPACITY]
 
   struct {
      T *   b
 
      T *   e
 
   }   p
 
u
 

Static Private Attributes

static constexpr std::size_t INTERNAL_CAPACITY = 2 * sizeof(T*) / sizeof(T)
 

Detailed Description

template<typename T, bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
class Xapian::Vec< T, COW, UNIQUEPTR, typename >

Suitable for "simple" type T.

T needs to be trivially copyable.

If sizeof(T) > 2 * sizeof(T*) this isn't going to work, and it's not very useful when sizeof(T) == 2 * sizeof(T*) as you can only store a single element inline.

Offers optional Copy-On-Write functionality - if COW is true, then copying a Vec with external data only makes a copy of that data if you attempt to modify it. Current COW is only supported for integral types T.

Offers optional unique pointer handling - if UNIQUEPTR is true it acts in a similar way to std::vector<std::unique_ptr<T>>.

Definition at line 62 of file smallvector.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
typedef const T* Xapian::Vec< T, COW, UNIQUEPTR, typename >::const_iterator

Definition at line 85 of file smallvector.h.

◆ iterator

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
typedef T* Xapian::Vec< T, COW, UNIQUEPTR, typename >::iterator

Definition at line 87 of file smallvector.h.

◆ size_type

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
typedef std::size_t Xapian::Vec< T, COW, UNIQUEPTR, typename >::size_type

Definition at line 83 of file smallvector.h.

Constructor & Destructor Documentation

◆ Vec() [1/5]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::Vec ( )
inline

Definition at line 89 of file smallvector.h.

◆ Vec() [2/5]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::Vec ( const Vec< T, COW, UNIQUEPTR, typename > &  )
delete

◆ Vec() [3/5]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::Vec ( const Vec_to_copy o)
inline

◆ Vec() [4/5]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::Vec ( Vec< T, COW, UNIQUEPTR, typename > &&  o)
inlinenoexcept

Definition at line 116 of file smallvector.h.

◆ Vec() [5/5]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::Vec ( size_type  n)
inlineexplicit

Definition at line 127 of file smallvector.h.

◆ ~Vec()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
Xapian::Vec< T, COW, UNIQUEPTR, typename >::~Vec ( )
inline

Definition at line 131 of file smallvector.h.

Member Function Documentation

◆ back()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const T& Xapian::Vec< T, COW, UNIQUEPTR, typename >::back ( ) const
inline

◆ begin() [1/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::begin ( )
inline

Definition at line 169 of file smallvector.h.

◆ begin() [2/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const_iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::begin ( ) const
inline

Definition at line 161 of file smallvector.h.

Referenced by Xapian::Internal::Context::shrink().

◆ capacity()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
size_type Xapian::Vec< T, COW, UNIQUEPTR, typename >::capacity ( ) const
inline

Definition at line 139 of file smallvector.h.

◆ cbegin()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const_iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::cbegin ( ) const
inline

Definition at line 153 of file smallvector.h.

◆ cend()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const_iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::cend ( ) const
inline

Definition at line 157 of file smallvector.h.

◆ clear()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::clear ( )
inline

Definition at line 219 of file smallvector.h.

◆ copy()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
template<bool ENABLE = !UNIQUEPTR>
auto Xapian::Vec< T, COW, UNIQUEPTR, typename >::copy ( ) const -> typename std::enable_if_t<ENABLE, Vec_to_copy>
inline

Definition at line 112 of file smallvector.h.

Referenced by InMemoryPositionList::assign().

◆ do_copy_from()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::do_copy_from ( const Vec< T, COW, UNIQUEPTR, typename > &  o)
inlineprotected

◆ do_cow()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::do_cow ( )
inlineprotected

Definition at line 379 of file smallvector.h.

◆ do_free()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::do_free ( )
inlineprotected

Definition at line 351 of file smallvector.h.

◆ do_reserve()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::do_reserve ( size_type  n)
inlineprotected

Definition at line 362 of file smallvector.h.

References rare.

◆ empty()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
bool Xapian::Vec< T, COW, UNIQUEPTR, typename >::empty ( ) const
inline

Definition at line 143 of file smallvector.h.

Referenced by GlassPositionListTable::pack(), and HoneyPositionTable::pack().

◆ end() [1/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::end ( )
inline

Definition at line 181 of file smallvector.h.

◆ end() [2/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const_iterator Xapian::Vec< T, COW, UNIQUEPTR, typename >::end ( ) const
inline

Definition at line 165 of file smallvector.h.

Referenced by Xapian::Internal::Context::shrink().

◆ erase() [1/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::erase ( const_iterator  b,
const_iterator  e 
)
inline

Definition at line 249 of file smallvector.h.

◆ erase() [2/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::erase ( const_iterator  it)
inline

Definition at line 229 of file smallvector.h.

References p.

Referenced by Xapian::Internal::Context::shrink().

◆ front()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const T& Xapian::Vec< T, COW, UNIQUEPTR, typename >::front ( ) const
inline

Definition at line 333 of file smallvector.h.

◆ insert()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::insert ( const_iterator  pos,
const T &  elt 
)
inline

Definition at line 273 of file smallvector.h.

References pos, and rare.

◆ is_external()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
bool Xapian::Vec< T, COW, UNIQUEPTR, typename >::is_external ( ) const
inlineprotectednoexcept

Return true if storage is external to the object.

Definition at line 402 of file smallvector.h.

Referenced by Xapian::Vec< T, COW, UNIQUEPTR, typename >::do_copy_from().

◆ operator=() [1/3]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::operator= ( const Vec< T, COW, UNIQUEPTR, typename > &  )
delete

◆ operator=() [2/3]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::operator= ( const Vec_to_copy o)
inline

◆ operator=() [3/3]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::operator= ( Vec< T, COW, UNIQUEPTR, typename > &&  o)
inline

Definition at line 121 of file smallvector.h.

◆ operator[]() [1/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
T& Xapian::Vec< T, COW, UNIQUEPTR, typename >::operator[] ( size_type  idx)
inline

Definition at line 324 of file smallvector.h.

◆ operator[]() [2/2]

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
const T& Xapian::Vec< T, COW, UNIQUEPTR, typename >::operator[] ( size_type  idx) const
inline

Definition at line 320 of file smallvector.h.

◆ pop_back()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::pop_back ( )
inline

Definition at line 206 of file smallvector.h.

◆ push_back()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::push_back ( elt)
inline

◆ release_at()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
template<bool ENABLE = !UNIQUEPTR>
T Xapian::Vec< T, COW, UNIQUEPTR, typename >::release_at ( size_type  idx)
inline

Definition at line 343 of file smallvector.h.

◆ reserve()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
void Xapian::Vec< T, COW, UNIQUEPTR, typename >::reserve ( size_type  n)
inline

◆ size()

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
size_type Xapian::Vec< T, COW, UNIQUEPTR, typename >::size ( ) const
inline

Member Data Documentation

◆ b

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
T* Xapian::Vec< T, COW, UNIQUEPTR, typename >::b

Definition at line 71 of file smallvector.h.

◆ c

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
std::size_t Xapian::Vec< T, COW, UNIQUEPTR, typename >::c = 0
private

◆ e

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
T* Xapian::Vec< T, COW, UNIQUEPTR, typename >::e

Definition at line 72 of file smallvector.h.

◆ INTERNAL_CAPACITY

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
constexpr std::size_t Xapian::Vec< T, COW, UNIQUEPTR, typename >::INTERNAL_CAPACITY = 2 * sizeof(T*) / sizeof(T)
staticconstexprprivate

Definition at line 66 of file smallvector.h.

◆ 

struct { ... } Xapian::Vec< T, COW, UNIQUEPTR, typename >::p

◆ 

union { ... } Xapian::Vec< T, COW, UNIQUEPTR, typename >::u

◆ v

template<typename T , bool COW = false, bool UNIQUEPTR = false, typename = typename std::enable_if_t< (std::is_trivially_copyable_v<T> && (!(COW && UNIQUEPTR)) && (!UNIQUEPTR || std::is_pointer_v<T>) && (!COW || std::is_integral_v<T>))>>
T Xapian::Vec< T, COW, UNIQUEPTR, typename >::v[INTERNAL_CAPACITY]

Definition at line 69 of file smallvector.h.


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