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

Static vector class. More...

#include <piranha/static_vector.hpp>

Public Types

using size_type = typename detail::static_vector_size_type< MaxSize >::type
 Size type. More...
 
typedef T value_type
 Contained type.
 
typedef value_typeiterator
 Iterator type.
 
typedef value_type const * const_iterator
 Const iterator type.
 

Public Member Functions

 static_vector ()
 Default constructor. More...
 
 static_vector (const static_vector &other)
 Copy constructor. More...
 
 static_vector (static_vector &&other) noexcept
 Move constructor. More...
 
 static_vector (const size_type &n, const value_type &x)
 Constructor from multiple copies. More...
 
 ~static_vector ()
 Destructor. More...
 
static_vectoroperator= (const static_vector &other)
 Copy assignment operator. More...
 
static_vectoroperator= (static_vector &&other) noexcept
 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...
 
iterator begin ()
 Begin iterator. More...
 
iterator end ()
 End iterator. More...
 
const_iterator begin () const
 Const begin iterator. More...
 
const_iterator end () const
 Const end iterator. More...
 
bool operator== (const static_vector &other) const
 Equality operator. More...
 
bool operator!= (const static_vector &other) const
 Inequality operator. More...
 
void push_back (const value_type &x)
 Copy-add element at the end of the vector. More...
 
void push_back (value_type &&x)
 Move-add element at the end of the vector. More...
 
template<typename... Args, emplace_enabler< Args... > = 0>
void emplace_back (Args &&... params)
 Construct in-place at the end of the vector. More...
 
size_type size () const
 Size. More...
 
bool empty () const
 Empty test. More...
 
void resize (const size_type &new_size)
 Resize. More...
 
iterator erase (const_iterator it)
 Erase element. More...
 
void clear ()
 Clear. More...
 
template<typename U = T, hash_enabler< U > = 0>
std::size_t hash () const
 Hash value. More...
 

Static Public Attributes

static const size_type max_size = MaxSize
 Maximum size. More...
 

Friends

template<typename U = T, ostream_enabler< U > = 0>
std::ostream & operator<< (std::ostream &os, const static_vector &v)
 Stream operator overload for piranha::static_vector. More...
 

Detailed Description

template<typename T, std::size_t MaxSize>
class piranha::static_vector< T, MaxSize >

Static vector class.

This class represents a dynamic array that avoids runtime memory allocation. Memory storage is provided by a contiguous memory block stored within the class. The size of the internal storage is enough to fit at least MaxSize objects.

The interface of this class mimics part of the interface of std::vector.

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 left in a state equivalent to a default-constructed instance.

Definition at line 99 of file static_vector.hpp.

Member Typedef Documentation

◆ size_type

template<typename T, std::size_t MaxSize>
using piranha::static_vector< T, MaxSize >::size_type = typename detail::static_vector_size_type<MaxSize>::type

Size type.

An unsigned integer type large enough to represent MaxSize.

Definition at line 112 of file static_vector.hpp.

Constructor & Destructor Documentation

◆ static_vector() [1/4]

template<typename T, std::size_t MaxSize>
piranha::static_vector< T, MaxSize >::static_vector ( )
inline

Default constructor.

Will construct a vector of size 0.

Definition at line 187 of file static_vector.hpp.

◆ static_vector() [2/4]

template<typename T, std::size_t MaxSize>
piranha::static_vector< T, MaxSize >::static_vector ( const static_vector< T, MaxSize > &  other)
inline

Copy constructor.

Parameters
othertarget of the copy operation.
Exceptions
unspecifiedany exception thrown by the copy constructor of T.

Definition at line 196 of file static_vector.hpp.

◆ static_vector() [3/4]

template<typename T, std::size_t MaxSize>
piranha::static_vector< T, MaxSize >::static_vector ( static_vector< T, MaxSize > &&  other)
inlinenoexcept

Move constructor.

Parameters
othertarget of the move operation.

Definition at line 226 of file static_vector.hpp.

◆ static_vector() [4/4]

template<typename T, std::size_t MaxSize>
piranha::static_vector< T, MaxSize >::static_vector ( const size_type n,
const value_type x 
)
inlineexplicit

Constructor from multiple copies.

Will construct a vector containing n copies of x.

Parameters
nnumber of copies of x that will be inserted in the vector.
xelement whose copies will be inserted in the vector.
Exceptions
unspecifiedany exception thrown by push_back().

Definition at line 252 of file static_vector.hpp.

◆ ~static_vector()

template<typename T, std::size_t MaxSize>
piranha::static_vector< T, MaxSize >::~static_vector ( )
inline

Destructor.

Will destroy all elements of the vector.

Definition at line 267 of file static_vector.hpp.

Member Function Documentation

◆ begin() [1/2]

template<typename T, std::size_t MaxSize>
iterator piranha::static_vector< T, MaxSize >::begin ( )
inline

Begin iterator.

Returns
iterator to the first element, or end() if the vector is empty.

Definition at line 368 of file static_vector.hpp.

◆ begin() [2/2]

template<typename T, std::size_t MaxSize>
const_iterator piranha::static_vector< T, MaxSize >::begin ( ) const
inline

Const begin iterator.

Returns
const iterator to the first element, or end() if the vector is empty.

Definition at line 384 of file static_vector.hpp.

◆ clear()

template<typename T, std::size_t MaxSize>
void piranha::static_vector< T, MaxSize >::clear ( )
inline

Clear.

This method will destroy all elements of the vector and set the size to zero.

Definition at line 588 of file static_vector.hpp.

◆ emplace_back()

template<typename T, std::size_t MaxSize>
template<typename... Args, emplace_enabler< Args... > = 0>
void piranha::static_vector< T, MaxSize >::emplace_back ( Args &&...  params)
inline

Construct in-place at the end of the vector.

Note
This method is enabled only if value_type is constructible from the variadic arguments pack.

Input parameters will be used to construct an instance of T at the end of the container.

Parameters
paramsarguments that will be used to construct the new element.
Exceptions
std::bad_allocif the insertion of the new element would lead to a size greater than MaxSize.
unspecifiedany exception thrown by the constructor of T from the input parameters.

Definition at line 473 of file static_vector.hpp.

◆ empty()

template<typename T, std::size_t MaxSize>
bool piranha::static_vector< T, MaxSize >::empty ( ) const
inline

Empty test.

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

Definition at line 493 of file static_vector.hpp.

◆ end() [1/2]

template<typename T, std::size_t MaxSize>
iterator piranha::static_vector< T, MaxSize >::end ( )
inline

End iterator.

Returns
iterator to the position one past the last element of the vector.

Definition at line 376 of file static_vector.hpp.

◆ end() [2/2]

template<typename T, std::size_t MaxSize>
const_iterator piranha::static_vector< T, MaxSize >::end ( ) const
inline

Const end iterator.

Returns
const iterator to the position one past the last element of the vector.

Definition at line 392 of file static_vector.hpp.

◆ erase()

template<typename T, std::size_t MaxSize>
iterator piranha::static_vector< T, MaxSize >::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 558 of file static_vector.hpp.

◆ hash()

template<typename T, std::size_t MaxSize>
template<typename U = T, hash_enabler< U > = 0>
std::size_t piranha::static_vector< T, MaxSize >::hash ( ) const
inline

Hash value.

Note
This method is enabled only if T satisfies piranha::is_hashable.
Returns
one of the following:
  • 0 if size() is 0,
  • the hash of the first element (via std::hash) if size() is 1,
  • in all other cases, the result of iteratively mixing via boost::hash_combine the hash values of all the elements of the container, calculated via std::hash, with the hash value of the first element as seed value.
Exceptions
unspecifiedany exception resulting from calculating the hash value(s) of the individual elements.
See also
http://www.boost.org/doc/libs/release/doc/html/hash/combine.html

Definition at line 617 of file static_vector.hpp.

◆ operator!=()

template<typename T, std::size_t MaxSize>
bool piranha::static_vector< T, MaxSize >::operator!= ( const static_vector< T, MaxSize > &  other) const
inline

Inequality operator.

Parameters
otherargument for the comparison.
Returns
the opposite of operator==().
Exceptions
unspecifiedany exception thrown by operator==().

Definition at line 417 of file static_vector.hpp.

◆ operator=() [1/2]

template<typename T, std::size_t MaxSize>
static_vector& piranha::static_vector< T, MaxSize >::operator= ( const static_vector< T, MaxSize > &  other)
inline

Copy assignment operator.

Parameters
othertarget of the copy assignment operation.
Returns
reference to this.
Exceptions
unspecifiedany exception thrown by the copy constructor of T.

Definition at line 283 of file static_vector.hpp.

◆ operator=() [2/2]

template<typename T, std::size_t MaxSize>
static_vector& piranha::static_vector< T, MaxSize >::operator= ( static_vector< T, MaxSize > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
othertarget of the move assignment operation.
Returns
reference to this.

Definition at line 307 of file static_vector.hpp.

◆ operator==()

template<typename T, std::size_t MaxSize>
bool piranha::static_vector< T, MaxSize >::operator== ( const static_vector< T, MaxSize > &  other) const
inline

Equality operator.

Parameters
otherargument for the comparison.
Returns
true if the sizes of the vectors are the same and all elements of this compare as equal to the elements in other, false otherwise.
Exceptions
unspecifiedany exception thrown by the comparison operator of the value type.

Definition at line 405 of file static_vector.hpp.

◆ operator[]() [1/2]

template<typename T, std::size_t MaxSize>
const value_type& piranha::static_vector< T, MaxSize >::operator[] ( const size_type n) const
inline

Const subscript operator.

Parameters
nindex of the desired element.
Returns
const reference to the element contained at index n;

Definition at line 350 of file static_vector.hpp.

◆ operator[]() [2/2]

template<typename T, std::size_t MaxSize>
value_type& piranha::static_vector< T, MaxSize >::operator[] ( const size_type n)
inline

Subscript operator.

Parameters
nindex of the desired element.
Returns
reference to the element contained at index n;

Definition at line 360 of file static_vector.hpp.

◆ push_back() [1/2]

template<typename T, std::size_t MaxSize>
void piranha::static_vector< T, MaxSize >::push_back ( const value_type x)
inline

Copy-add element at the end of the vector.

x is copy-inserted at the end of the container.

Parameters
xelement to be inserted.
Exceptions
std::bad_allocif the insertion of x would lead to a size greater than MaxSize.
unspecifiedany exception thrown by the copy constructor of T.

Definition at line 430 of file static_vector.hpp.

◆ push_back() [2/2]

template<typename T, std::size_t MaxSize>
void piranha::static_vector< T, MaxSize >::push_back ( value_type &&  x)
inline

Move-add element at the end of the vector.

x is move-inserted at the end of the container.

Parameters
xelement to be inserted.
Exceptions
std::bad_allocif the insertion of x would lead to a size greater than MaxSize.

Definition at line 446 of file static_vector.hpp.

◆ resize()

template<typename T, std::size_t MaxSize>
void piranha::static_vector< T, MaxSize >::resize ( const size_type new_size)
inline

Resize.

After this operation, the number of elements stored in the container will be new_size. If new_size is greater than the size of the object before the operation, the new elements will be value-initialized and placed at the end of the container. If new_size is smaller than the size of the object before the operation, the first new_size object in the vector will be preserved.

Parameters
new_sizenew size for the vector.
Exceptions
std::bad_allocif new_size is greater than MaxSize.
unspecifiedany exception thrown by the default constructor of T.

Definition at line 509 of file static_vector.hpp.

◆ size()

template<typename T, std::size_t MaxSize>
size_type piranha::static_vector< T, MaxSize >::size ( ) const
inline

Size.

Returns
the number of elements currently stored in this.

Definition at line 485 of file static_vector.hpp.

Friends And Related Function Documentation

◆ operator<<

template<typename T, std::size_t MaxSize>
template<typename U = T, ostream_enabler< U > = 0>
std::ostream& operator<< ( std::ostream &  os,
const static_vector< T, MaxSize > &  v 
)
friend

Stream operator overload for piranha::static_vector.

Note
This function is enabled only if U satisfies piranha::is_ostreamable.

Will print to stream a human-readable representation of v.

Parameters
ostarget stream.
vvector to be streamed.
Returns
reference to os.
Exceptions
unspecifiedany exception thrown by printing to stream instances of the value type of v.

Definition at line 642 of file static_vector.hpp.

Member Data Documentation

◆ max_size

template<typename T, std::size_t MaxSize>
const static_vector< T, MaxSize >::size_type piranha::static_vector< T, MaxSize >::max_size = MaxSize
static

Maximum size.

Alias for MaxSize.

Definition at line 176 of file static_vector.hpp.


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