Clingo
Loading...
Searching...
No Matches
CppClingo::Util::immutable_array< T > Class Template Reference

An immutable array with efficient copying. More...

#include <immutable_array.hh>

Public Types

using value_type = typename vector_type::value_type
 The value type.
 
using const_reference = typename vector_type::const_reference
 The reference type.
 
using allocator_type = typename vector_type::allocator_type
 The allocator type.
 
using size_type = typename vector_type::size_type
 The unsigned size type.
 
using difference_type = typename vector_type::difference_type
 The signed size type.
 
using const_pointer = typename vector_type::const_pointer
 The pointer type.
 
using const_iterator = typename vector_type::const_iterator
 Theconst iterator type.
 

Public Member Functions

constexpr immutable_array () noexcept=default
 Construct an empty array.
 
 immutable_array (immutable_array const &other) noexcept=default
 Copy construct the array.
 
 immutable_array (immutable_array &&other) noexcept=default
 Move construct the array.
 
auto operator= (immutable_array const &other) noexcept -> immutable_array &=default
 Copy assign the array.
 
auto operator= (immutable_array &&other) noexcept -> immutable_array &=default
 Move assign the array.
 
 immutable_array (std::span< T > span)
 Construct array copying values from the given span.
 
 immutable_array (std::span< T const > span)
 Construct array copying values from the given span.
 
 immutable_array (std::vector< T > &&vec)
 Construct array taking ownership of the given vector.
 
 immutable_array (std::vector< T > const &vec)
 Construct array copying from the given vector.
 
 immutable_array (std::initializer_list< T > init)
 Construct array coping from the given initializer list.
 
template<class It >
 immutable_array (It first, It last)
 Construct array coping from the given iterator range.
 
template<class It , class Pred >
 immutable_array (It first, It last, Pred conv)
 Construct array coping from the given iterator range.
 
auto at (size_type pos) const -> const_reference
 Get the element at the given index.
 
auto operator[] (size_type pos) const -> const_reference
 Get the element at the given index.
 
auto front () const -> const_reference
 Get a reference to the first element.
 
auto back () const -> const_reference
 Get a reference to the last element.
 
auto data () const -> T const *
 Get a pointer to the undelying data.
 
auto begin () const noexcept -> const_iterator
 Get an iterator pointing to the beginning of the array.
 
auto end () const noexcept -> const_iterator
 Get an iterator pointing to the end of the array.
 
auto empty () const noexcept -> bool
 Check if the array is empty.
 
auto size () const noexcept -> size_type
 Get the size of the array.
 
void swap (immutable_array &other) noexcept
 Swap two immutable arrays.
 

Friends

auto operator== (immutable_array const &lhs, immutable_array const &rhs) -> bool
 Compare two vectors.
 
auto operator<=> (immutable_array const &lhs, immutable_array const &rhs)
 Compare two vectors lexicographically.
 

Detailed Description

template<typename T>
class CppClingo::Util::immutable_array< T >

An immutable array with efficient copying.

Note that this can be implemented more efficiently avoiding the double indirection.

Constructor & Destructor Documentation

◆ immutable_array()

template<typename T >
CppClingo::Util::immutable_array< T >::immutable_array ( std::vector< T > &&  vec)
inline

Construct array taking ownership of the given vector.

Note that this might change in case the data type is implemented differently.

Member Function Documentation

◆ at()

template<typename T >
auto CppClingo::Util::immutable_array< T >::at ( size_type  pos) const -> const_reference
inline

Get the element at the given index.

Throws in case the index is to large.


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