piranha  0.10
Public Types | Public Member Functions | Static Public Attributes | List of all members
piranha::small_vector< T, S > Class Template Reference

Small vector class. More...

#include <piranha/small_vector.hpp>

Public Types

using size_type = size_type_impl
 A fundamental unsigned integer type representing the number of elements stored in the vector.
 
using value_type = T
 Alias for T.
 
using iterator = value_type *
 Iterator type.
 
using const_iterator = value_type const *
 Const iterator type.
 

Public Member Functions

 small_vector ()=default
 Default constructor. More...
 
 small_vector (const small_vector &other)=default
 Copy constructor. More...
 
 small_vector (small_vector &&other)=default
 Move constructor. More...
 
template<typename U , init_list_enabler< U > = 0>
 small_vector (std::initializer_list< U > l)
 Constructor from initializer list. More...
 
 small_vector (const size_type &size, const T &value)
 Constructor from size and value. More...
 
 ~small_vector ()=default
 Destructor.
 
small_vectoroperator= (const small_vector &)=default
 Copy assignment operator. More...
 
small_vectoroperator= (small_vector &&)=default
 Move assignment operator. More...
 
const value_typeoperator[] (const size_type &n) const
 Const subscript operator. More...
 
value_typeoperator[] (const size_type &n)
 Subscript operator. More...
 
void push_back (const value_type &x)
 Copy-add element at the end. More...
 
void push_back (value_type &&x)
 Move-add element at the end. More...
 
iterator begin ()
 Mutable begin iterator. More...
 
iterator end ()
 Mutable end iterator. More...
 
const_iterator begin () const
 Const begin iterator. More...
 
const_iterator end () const
 Const end iterator. More...
 
size_type size () const
 Size. More...
 
bool is_static () const
 Static storage flag. More...
 
template<typename U = value_type, equality_enabler< U > = 0>
bool operator== (const small_vector &other) const
 Equality operator. More...
 
template<typename U = value_type, equality_enabler< U > = 0>
bool operator!= (const small_vector &other) const
 Inequality operator. More...
 
template<typename U = value_type, hash_enabler< U > = 0>
std::size_t hash () const
 Hash method. More...
 
bool empty () const
 Empty test. More...
 
void resize (const size_type &size)
 Resize. More...
 
template<typename U = value_type, add_enabler< U > = 0>
void add (small_vector &retval, const small_vector &other) const
 Vector addition. More...
 
template<typename U = value_type, sub_enabler< U > = 0>
void sub (small_vector &retval, const small_vector &other) const
 Vector subtraction. More...
 
iterator erase (const_iterator it)
 Erase element. More...
 
std::tuple< size_type, iterator, iteratorsize_begin_end ()
 Size, begin and end. More...
 
std::tuple< size_type, const_iterator, const_iteratorsize_begin_end () const
 Size, begin and end (const version). More...
 

Static Public Attributes

static const std::decay< decltype(s_storage::max_size)>::type max_static_size = s_storage::max_size
 Maximum number of elements that can be stored in static storage.
 
static const std::decay< decltype(d_storage::max_size)>::type max_dynamic_size = d_storage::max_size
 Maximum number of elements that can be stored in dynamic storage.
 
static const size_type max_size = get_max<size_type>(max_static_size, max_dynamic_size)
 Maximum number of elements that can be stored.
 

Detailed Description

template<typename T, typename S = std::integral_constant<std::size_t, 0u>>
class piranha::small_vector< T, S >

Small vector class.

This class is a sequence container similar to the standard std::vector class. The class will avoid dynamic memory allocation by using internal static storage up to a certain number of stored elements. If S is a zero integral constant, this number is calculated automatically (but it will always be at least 1). Otherwise, the limit number is set to S::value.

Type requirements

Exception safety guarantee

Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.

Move semantics

After a move operation, the container will be empty.

Definition at line 45 of file small_vector_fwd.hpp.

Constructor & Destructor Documentation

◆ small_vector() [1/5]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
piranha::small_vector< T, S >::small_vector ( )
default

Default constructor.

Will initialise an empty vector with internal static storage.

◆ small_vector() [2/5]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
piranha::small_vector< T, S >::small_vector ( const small_vector< T, S > &  other)
default

Copy constructor.

The storage type after successful construction will be the same of other.

Parameters
otherconstruction argument.
Exceptions
std::bad_allocin case of memory allocation errors.
unspecifiedany exception thrown by the copy constructor of T.

◆ small_vector() [3/5]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
piranha::small_vector< T, S >::small_vector ( small_vector< T, S > &&  other)
default

Move constructor.

The storage type after successful construction will be the same of other.

Parameters
otherconstruction argument.

◆ small_vector() [4/5]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U , init_list_enabler< U > = 0>
piranha::small_vector< T, S >::small_vector ( std::initializer_list< U >  l)
inlineexplicit

Constructor from initializer list.

Note
This constructor is enabled only if U is safely convertible to T.

The elements of l will be added to a default-constructed object, after conversion to T via piranha::safe_cast().

Parameters
llist that will be used for initialisation.
Exceptions
unspecifiedany exception thrown by push_back() or by piranha::safe_cast().

Definition at line 676 of file small_vector.hpp.

◆ small_vector() [5/5]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
piranha::small_vector< T, S >::small_vector ( const size_type size,
const T &  value 
)
inlineexplicit

Constructor from size and value.

This constructor will initialise a vector containing size copies of value.

Parameters
sizethe desired vector size.
valuethe value used to initialise all the elements of the vector.
Exceptions
unspecifiedany exception thrown by push_back().

Definition at line 692 of file small_vector.hpp.

Member Function Documentation

◆ add()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = value_type, add_enabler< U > = 0>
void piranha::small_vector< T, S >::add ( small_vector< T, S > &  retval,
const small_vector< T, S > &  other 
) const
inline

Vector addition.

Note
This method is enabled only if value_type satisfies piranha::has_add3.

Will compute the element-wise addition of this and other via piranha::math::add3(), storing the result in retval. In face of exceptions during the addition of two elements, retval will be left in an unspecified but valid state, provided that piranha::math::add3() offers the basic exception safety guarantee.

this, retval and/or other are allowed to be the same object, provided that piranha::math::add3() also supports this type of usage.

Parameters
retvalresult of the addition.
otherargument for the addition.
Exceptions
std::invalid_argumentif the sizes of this and other do not coincide.
unspecifiedany exception thrown by:

Definition at line 967 of file small_vector.hpp.

◆ begin() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
iterator piranha::small_vector< T, S >::begin ( )
inline

Mutable begin iterator.

Returns
iterator to the beginning of the vector.

Definition at line 761 of file small_vector.hpp.

◆ begin() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
const_iterator piranha::small_vector< T, S >::begin ( ) const
inline

Const begin iterator.

Returns
iterator to the beginning of the vector.

Definition at line 785 of file small_vector.hpp.

◆ empty()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::small_vector< T, S >::empty ( ) const
inline

Empty test.

Returns
true if the size of the container is zero, false otherwise.

Definition at line 896 of file small_vector.hpp.

◆ end() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
iterator piranha::small_vector< T, S >::end ( )
inline

Mutable end iterator.

Returns
iterator to the end of the vector.

Definition at line 773 of file small_vector.hpp.

◆ end() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
const_iterator piranha::small_vector< T, S >::end ( ) const
inline

Const end iterator.

Returns
iterator to the end of the vector.

Definition at line 797 of file small_vector.hpp.

◆ erase()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
iterator piranha::small_vector< T, S >::erase ( const_iterator  it)
inline

Erase element.

This method will erase the element to which it points. The return value will be the iterator following the erased element (which will be the end iterator if it points to the last element of the vector).

it must be a valid iterator to an element in this.

Parameters
ititerator to the element of this to be removed.
Returns
the iterator following the erased element.

Definition at line 1027 of file small_vector.hpp.

◆ hash()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = value_type, hash_enabler< U > = 0>
std::size_t piranha::small_vector< T, S >::hash ( ) const
inline

Hash method.

Note
This method is enabled only if value_type satisfies piranha::is_hashable.
Returns
a hash value for this.

Definition at line 884 of file small_vector.hpp.

◆ is_static()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::small_vector< T, S >::is_static ( ) const
inline

Static storage flag.

Returns
true if the storage being used is the static one, false otherwise.

Definition at line 821 of file small_vector.hpp.

◆ operator!=()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = value_type, equality_enabler< U > = 0>
bool piranha::small_vector< T, S >::operator!= ( const small_vector< T, S > &  other) const
inline

Inequality operator.

Note
This method is enabled only if T is equality comparable.
Parameters
otherargument for the comparison.
Returns
the opposite of operator==().
Exceptions
unspecifiedany exception thrown by operator==().

Definition at line 872 of file small_vector.hpp.

◆ operator=() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
small_vector& piranha::small_vector< T, S >::operator= ( const small_vector< T, S > &  )
default

Copy assignment operator.

Returns
reference to this.
Exceptions
unspecifiedany exception thrown by the copy constructor.

◆ operator=() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
small_vector& piranha::small_vector< T, S >::operator= ( small_vector< T, S > &&  )
default

Move assignment operator.

Returns
reference to this.

◆ operator==()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = value_type, equality_enabler< U > = 0>
bool piranha::small_vector< T, S >::operator== ( const small_vector< T, S > &  other) const
inline

Equality operator.

Note
This method is enabled only if T is equality comparable.
Parameters
otherargument for the comparison.
Returns
true if the sizes of this and other coincide and the element-wise comparison of the stored objects is true, false otherwise.
Exceptions
unspecifiedany exception thrown by the equality operator of T.

Definition at line 838 of file small_vector.hpp.

◆ operator[]() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
const value_type& piranha::small_vector< T, S >::operator[] ( const size_type n) const
inline

Const subscript operator.

Parameters
nindex of the element to be accessed.
Returns
const reference to the n-th element of the vector.

Definition at line 718 of file small_vector.hpp.

◆ operator[]() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
value_type& piranha::small_vector< T, S >::operator[] ( const size_type n)
inline

Subscript operator.

Parameters
nindex of the element to be accessed.
Returns
reference to the n-th element of the vector.

Definition at line 728 of file small_vector.hpp.

◆ push_back() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
void piranha::small_vector< T, S >::push_back ( const value_type x)
inline

Copy-add element at the end.

NOTE: if x is an element of the vector, the behaviour will be undefined.

Parameters
xobject that will be added at the end of the vector.
Exceptions
std::bad_allocin case of memory allocation errors or if the size limit is exceeded.
unspecifiedany exception thrown by the copy constructor of T.

Definition at line 741 of file small_vector.hpp.

◆ push_back() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
void piranha::small_vector< T, S >::push_back ( value_type &&  x)
inline

Move-add element at the end.

NOTE: if x is an element of the vector, the behaviour will be undefined.

Parameters
xobject that will be added at the end of the vector.
Exceptions
std::bad_allocin case of memory allocation errors or if the size limit is exceeded.

Definition at line 753 of file small_vector.hpp.

◆ resize()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
void piranha::small_vector< T, S >::resize ( const size_type size)
inline

Resize.

Resize the vector to size. Elements in excess will be destroyed, new elements will be value-initialised and placed at the end.

Parameters
sizenew size.
Exceptions
std::bad_allocin case of memory allocation errors or if the size limit is exceeded.
unspecifiedany exception thrown by the default constructor of T.

Definition at line 914 of file small_vector.hpp.

◆ size()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
size_type piranha::small_vector< T, S >::size ( ) const
inline

Size.

Returns
number of elements stored in the vector.

Definition at line 809 of file small_vector.hpp.

◆ size_begin_end() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
std::tuple<size_type, iterator, iterator> piranha::small_vector< T, S >::size_begin_end ( )
inline

Size, begin and end.

Returns
a tuple containing the size and the begin and the end iterators.

Definition at line 1039 of file small_vector.hpp.

◆ size_begin_end() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
std::tuple<size_type, const_iterator, const_iterator> piranha::small_vector< T, S >::size_begin_end ( ) const
inline

Size, begin and end (const version).

Returns
a tuple containing the size and the begin and the end const iterators.

Definition at line 1051 of file small_vector.hpp.

◆ sub()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = value_type, sub_enabler< U > = 0>
void piranha::small_vector< T, S >::sub ( small_vector< T, S > &  retval,
const small_vector< T, S > &  other 
) const
inline

Vector subtraction.

Note
This method is enabled only if value_type satisfies piranha::has_sub3.

Will compute the element-wise subtraction of this and other via piranha::math::sub3(), storing the result in retval. In face of exceptions during the subtraction of two elements, retval will be left in an unspecified but valid state, provided that piranha::math::sub3() offers the basic exception safety guarantee.

this, retval and/or other are allowed to be the same object, provided that piranha::math::sub3() also supports this type of usage.

Parameters
retvalresult of the subtraction.
otherargument for the subtraction.
Exceptions
std::invalid_argumentif the sizes of this and other do not coincide.
unspecifiedany exception thrown by:

Definition at line 1003 of file small_vector.hpp.


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