Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

immer::array< T, MemoryPolicy > Class Template Reference

#include <array.hpp>

Public Types

using value_type = T
 
using reference = const T &
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using const_reference = const T &
 
using iterator = const T *
 
using const_iterator = iterator
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using memory_policy = MemoryPolicy
 
using transient_type = array_transient< T, MemoryPolicy >
 

Public Member Functions

 array ()=default
 
 array (std::initializer_list< T > values)
 
template<typename Iter , typename Sent , std::enable_if_t< detail::compatible_sentinel_v< Iter, Sent > &&detail::is_forward_iterator_v< Iter >, bool > = true>
 array (Iter first, Sent last)
 
 array (size_type n, T v={})
 
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
std::size_t size () const
 
bool empty () const
 
const T * data () const
 
const T & back () const
 
const T & front () const
 
reference operator[] (size_type index) const
 
reference at (size_type index) const
 
bool operator== (const array &other) const
 
bool operator!= (const array &other) const
 
array push_back (value_type value) const &
 
decltype(auto) push_back (value_type value) &&
 
array set (std::size_t index, value_type value) const &
 
decltype(auto) set (size_type index, value_type value) &&
 
template<typename FnT >
array update (std::size_t index, FnT &&fn) const &
 
template<typename FnT >
decltype(auto) update (size_type index, FnT &&fn) &&
 
array take (size_type elems) const &
 
decltype(auto) take (size_type elems) &&
 
transient_type transient () const &
 
transient_type transient () &&
 
const impl_timpl () const
 

Private Types

using impl_t = std::conditional_t< MemoryPolicy::use_transient_rvalues, detail::arrays::with_capacity< T, MemoryPolicy >, detail::arrays::no_capacity< T, MemoryPolicy > >
 
using move_t = std::integral_constant< bool, MemoryPolicy::use_transient_rvalues >
 

Private Member Functions

 array (impl_t impl)
 
array && push_back_move (std::true_type, value_type value)
 
array push_back_move (std::false_type, value_type value)
 
array && set_move (std::true_type, size_type index, value_type value)
 
array set_move (std::false_type, size_type index, value_type value)
 
template<typename Fn >
array && update_move (std::true_type, size_type index, Fn &&fn)
 
template<typename Fn >
array update_move (std::false_type, size_type index, Fn &&fn)
 
array && take_move (std::true_type, size_type elems)
 
array take_move (std::false_type, size_type elems)
 

Private Attributes

friend transient_type
 
impl_t impl_ = impl_t::empty()
 

Detailed Description

template<typename T, typename MemoryPolicy = default_memory_policy>
class immer::array< T, MemoryPolicy >

Immutable container that stores a sequence of elements in contiguous memory.

Template Parameters
TThe type of the values to be stored in the container.

It supports the most efficient iteration and random access, equivalent to a std::vector or std::array, but all manipulations are :math:O(size).

.. tip:: Don't be fooled by the bad complexity of this data structure. It is a great choice for short sequence or when it is seldom or never changed. This depends on the sizeof(T) and the expensiveness of its T's copy constructor, in case of doubt, measure. For basic types, using an array when :math:n < 100 is a good heuristic.

Definition at line 41 of file array.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::const_iterator = iterator

Definition at line 59 of file array.hpp.

◆ const_reference

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::const_reference = const T&

Definition at line 56 of file array.hpp.

◆ difference_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::difference_type = std::ptrdiff_t

Definition at line 55 of file array.hpp.

◆ impl_t

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::impl_t = std::conditional_t< MemoryPolicy::use_transient_rvalues, detail::arrays::with_capacity<T, MemoryPolicy>, detail::arrays::no_capacity<T, MemoryPolicy> >
private

Definition at line 46 of file array.hpp.

◆ iterator

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::iterator = const T*

Definition at line 58 of file array.hpp.

◆ memory_policy

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::memory_policy = MemoryPolicy

Definition at line 62 of file array.hpp.

◆ move_t

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::move_t = std::integral_constant<bool, MemoryPolicy::use_transient_rvalues>
private

Definition at line 49 of file array.hpp.

◆ reference

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::reference = const T&

Definition at line 53 of file array.hpp.

◆ reverse_iterator

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 60 of file array.hpp.

◆ size_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::size_type = std::size_t

Definition at line 54 of file array.hpp.

◆ transient_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::transient_type = array_transient<T, MemoryPolicy>

Definition at line 63 of file array.hpp.

◆ value_type

template<typename T , typename MemoryPolicy = default_memory_policy>
using immer::array< T, MemoryPolicy >::value_type = T

Definition at line 52 of file array.hpp.

Constructor & Destructor Documentation

◆ array() [1/5]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::array< T, MemoryPolicy >::array ( )
default

Default constructor. It creates an array of size() == 0. It does not allocate memory and its complexity is $ O(1) $.

◆ array() [2/5]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::array< T, MemoryPolicy >::array ( std::initializer_list< T >  values)
inline

Constructs an array containing the elements in values.

Definition at line 74 of file array.hpp.

◆ array() [3/5]

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename Iter , typename Sent , std::enable_if_t< detail::compatible_sentinel_v< Iter, Sent > &&detail::is_forward_iterator_v< Iter >, bool > = true>
immer::array< T, MemoryPolicy >::array ( Iter  first,
Sent  last 
)
inline

Constructs a array containing the elements in the range defined by the forward iterator first and range sentinel last.

Definition at line 86 of file array.hpp.

◆ array() [4/5]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::array< T, MemoryPolicy >::array ( size_type  n,
v = {} 
)
inline

Constructs a array containing the element val repeated n times.

Definition at line 94 of file array.hpp.

◆ array() [5/5]

template<typename T , typename MemoryPolicy = default_memory_policy>
immer::array< T, MemoryPolicy >::array ( impl_t  impl)
inlineprivate

Definition at line 283 of file array.hpp.

Member Function Documentation

◆ at()

template<typename T , typename MemoryPolicy = default_memory_policy>
reference immer::array< T, MemoryPolicy >::at ( size_type  index) const
inline

Returns a const reference to the element at position index. It throws an std::out_of_range exception when $ index \geq size() $. It does not allocate memory and its complexity is effectively $ O(1) $.

Definition at line 167 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ back()

template<typename T , typename MemoryPolicy = default_memory_policy>
const T& immer::array< T, MemoryPolicy >::back ( ) const
inline

Access the last element.

Definition at line 145 of file array.hpp.

References immer::array< T, MemoryPolicy >::data(), and immer::array< T, MemoryPolicy >::size().

◆ begin()

template<typename T , typename MemoryPolicy = default_memory_policy>
iterator immer::array< T, MemoryPolicy >::begin ( ) const
inline

Returns an iterator pointing at the first element of the collection. It does not allocate memory and its complexity is $ O(1) $.

Definition at line 103 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::rend().

◆ data()

template<typename T , typename MemoryPolicy = default_memory_policy>
const T* immer::array< T, MemoryPolicy >::data ( ) const
inline

Access the raw data.

Definition at line 140 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::back(), and immer::array< T, MemoryPolicy >::front().

◆ empty()

template<typename T , typename MemoryPolicy = default_memory_policy>
bool immer::array< T, MemoryPolicy >::empty ( ) const
inline

Returns true if there are no elements in the container. It does not allocate memory and its complexity is $ O(1) $.

Definition at line 135 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ end()

template<typename T , typename MemoryPolicy = default_memory_policy>
iterator immer::array< T, MemoryPolicy >::end ( ) const
inline

Returns an iterator pointing just after the last element of the collection. It does not allocate and its complexity is $ O(1) $.

Definition at line 109 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::rbegin().

◆ front()

template<typename T , typename MemoryPolicy = default_memory_policy>
const T& immer::array< T, MemoryPolicy >::front ( ) const
inline

Access the first element.

Definition at line 150 of file array.hpp.

References immer::array< T, MemoryPolicy >::data().

◆ impl()

template<typename T , typename MemoryPolicy = default_memory_policy>
const impl_t& immer::array< T, MemoryPolicy >::impl ( ) const
inline

Definition at line 278 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ operator!=()

template<typename T , typename MemoryPolicy = default_memory_policy>
bool immer::array< T, MemoryPolicy >::operator!= ( const array< T, MemoryPolicy > &  other) const
inline

Definition at line 175 of file array.hpp.

◆ operator==()

template<typename T , typename MemoryPolicy = default_memory_policy>
bool immer::array< T, MemoryPolicy >::operator== ( const array< T, MemoryPolicy > &  other) const
inline

Returns whether the vectors are equal.

Definition at line 173 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ operator[]()

template<typename T , typename MemoryPolicy = default_memory_policy>
reference immer::array< T, MemoryPolicy >::operator[] ( size_type  index) const
inline

Returns a const reference to the element at position index. It is undefined when $ 0 index \geq size() $. It does not allocate memory and its complexity is effectively $ O(1) $.

Definition at line 158 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ push_back() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::push_back ( value_type  value) const &
inline

Returns an array with value inserted at the end. It may allocate memory and its complexity is $ O(size) $.

Example .. literalinclude:: ../example/array/array.cpp :language: c++ :dedent: 8 :start-after: push-back/start :end-before: push-back/end

Definition at line 193 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ push_back() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
decltype(auto) immer::array< T, MemoryPolicy >::push_back ( value_type  value) &&
inline

Definition at line 196 of file array.hpp.

References immer::array< T, MemoryPolicy >::push_back_move().

◆ push_back_move() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array&& immer::array< T, MemoryPolicy >::push_back_move ( std::true_type  ,
value_type  value 
)
inlineprivate

◆ push_back_move() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::push_back_move ( std::false_type  ,
value_type  value 
)
inlineprivate

Definition at line 287 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ rbegin()

template<typename T , typename MemoryPolicy = default_memory_policy>
reverse_iterator immer::array< T, MemoryPolicy >::rbegin ( ) const
inline

Returns an iterator that traverses the collection backwards, pointing at the first element of the reversed collection. It does not allocate memory and its complexity is $ O(1) $.

Definition at line 116 of file array.hpp.

References immer::array< T, MemoryPolicy >::end().

◆ rend()

template<typename T , typename MemoryPolicy = default_memory_policy>
reverse_iterator immer::array< T, MemoryPolicy >::rend ( ) const
inline

Returns an iterator that traverses the collection backwards, pointing after the last element of the reversed collection. It does not allocate memory and its complexity is $ O(1) $.

Definition at line 123 of file array.hpp.

References immer::array< T, MemoryPolicy >::begin().

◆ set() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::set ( std::size_t  index,
value_type  value 
) const &
inline

Returns an array containing value value at position idx. Undefined for index >= size(). It may allocate memory and its complexity is $ O(size) $.

Example .. literalinclude:: ../example/array/array.cpp :language: c++ :dedent: 8 :start-after: set/start :end-before: set/end

Definition at line 215 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ set() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
decltype(auto) immer::array< T, MemoryPolicy >::set ( size_type  index,
value_type  value 
) &&
inline

Definition at line 218 of file array.hpp.

References immer::array< T, MemoryPolicy >::set_move().

◆ set_move() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array&& immer::array< T, MemoryPolicy >::set_move ( std::true_type  ,
size_type  index,
value_type  value 
)
inlineprivate

Definition at line 290 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::set().

◆ set_move() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::set_move ( std::false_type  ,
size_type  index,
value_type  value 
)
inlineprivate

Definition at line 292 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ size()

template<typename T , typename MemoryPolicy = default_memory_policy>
std::size_t immer::array< T, MemoryPolicy >::size ( ) const
inline

Returns the number of elements in the container. It does not allocate memory and its complexity is $ O(1) $.

Definition at line 129 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::back().

◆ take() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::take ( size_type  elems) const &
inline

Returns a array containing only the first min(elems, size()) elements. It may allocate memory and its complexity is effectively $ O(1) $.

Example .. literalinclude:: ../example/array/array.cpp :language: c++ :dedent: 8 :start-after: take/start :end-before: take/end

Definition at line 262 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ take() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
decltype(auto) immer::array< T, MemoryPolicy >::take ( size_type  elems) &&
inline

Definition at line 265 of file array.hpp.

References immer::array< T, MemoryPolicy >::take_move().

◆ take_move() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array&& immer::array< T, MemoryPolicy >::take_move ( std::true_type  ,
size_type  elems 
)
inlineprivate

Definition at line 302 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Referenced by immer::array< T, MemoryPolicy >::take().

◆ take_move() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
array immer::array< T, MemoryPolicy >::take_move ( std::false_type  ,
size_type  elems 
)
inlineprivate

Definition at line 304 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ transient() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
transient_type immer::array< T, MemoryPolicy >::transient ( ) const &
inline

Returns an transient form of this container, an immer::array_transient.

Definition at line 272 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ transient() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
transient_type immer::array< T, MemoryPolicy >::transient ( ) &&
inline

Definition at line 274 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ update() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename FnT >
array immer::array< T, MemoryPolicy >::update ( std::size_t  index,
FnT &&  fn 
) const &
inline

Returns an array containing the result of the expression fn((*this)[idx]) at position idx. Undefined for index >= size(). It may allocate memory and its complexity is $ O(size) $.

Example .. literalinclude:: ../example/array/array.cpp :language: c++ :dedent: 8 :start-after: update/start :end-before: update/end

Definition at line 239 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

◆ update() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename FnT >
decltype(auto) immer::array< T, MemoryPolicy >::update ( size_type  index,
FnT &&  fn 
) &&
inline

Definition at line 243 of file array.hpp.

References immer::array< T, MemoryPolicy >::update_move().

◆ update_move() [1/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename Fn >
array&& immer::array< T, MemoryPolicy >::update_move ( std::true_type  ,
size_type  index,
Fn &&  fn 
)
inlineprivate

◆ update_move() [2/2]

template<typename T , typename MemoryPolicy = default_memory_policy>
template<typename Fn >
array immer::array< T, MemoryPolicy >::update_move ( std::false_type  ,
size_type  index,
Fn &&  fn 
)
inlineprivate

Definition at line 299 of file array.hpp.

References immer::array< T, MemoryPolicy >::impl_.

Member Data Documentation

◆ impl_

◆ transient_type

template<typename T , typename MemoryPolicy = default_memory_policy>
friend immer::array< T, MemoryPolicy >::transient_type
private

Definition at line 281 of file array.hpp.


The documentation for this class was generated from the following file:
Released under the MIT license