Skip to content

HolorRef class

Defined in header holor/holor_ref.h, within the namespace holor.

    template<typename T, size_t N> requires (N>0)
    class HolorRef;

This class implements a general N-dimensional container that doesn't own the memory where the elements are stored. The elements in the container need not to be numerical types, but can be of a generic type T. Holors are implemented with a row-major representation, i.e., the elements of the last dimension of the container are contiguous.


Template parameters

Name Description
N number of dimensions of the container. It must be N>0
T type of the elements stored in the container

Member types and aliases

Name Description
order number of dimensions in the container (equal to N)
value_type type of the elements in the container (equal to T)
iterator type of the iterator for the container
const_iterator type of the const_iterator for the container
reverse_iterator type of the reverse_iterator for the container
const_reverse_iterator type of the const_reverse_iterator for the container

Public Member functions

Constructors

signature
  1.     HolorRef();
    
  2.     HolorRef(const HolorRef<T, N>& holor_ref);
    
  3.     HolorRef(HolorRef<T, N>&& holor_ref);
    
  4.     HolorRef(T* dataptr, const Layout<N>& layout);
    
  5.     template <class Container> requires assert::SizedTypedContainer<Container, size_t, N>
        explicit HolorRef(T* dataptr, const Container& lengths);
    
  6.     template <class Container> requires assert::ResizeableTypedContainer<Container, size_t>
        explicit HolorRef(T* dataptr, const Container& lengths);
    
brief

Create a HolorRef object, either as an empty HolorRef with 0-length dimensions (1), or initializing it from another HolorRef (2, 3), or creating it from a pointer to a memory location and a Layout (4), or by creating it from a pointer to a memory location and a container of lengths.

parameters
  • holor_ref: HolorRef object used to initialize the created HolorRef.
  • dataptr: pointer to the memory location where the elements are stored.
  • layout: Layout used to initialize the way coordinates are mapped to memory locations.
  • lenghts: number of elements along each individual dimension of the HolorRef container, given either as a compile-time size container (e.g. a std::array) or as a dynamic size container (e.g., a std::vector).
return

A HolorRef container.


Assignments

signature
  1.     HolorRef& operator=(HolorRef<T, N>&& holor_ref);
    
  2.     HolorRef& operator=(HolorRef<T, N>&& holor_ref);
    
brief

Assign to a HolorRef.

parameters
  • holor_ref: HolorRef object to assign from.
return

A reference to a HolorRef.


Iterators

begin

signature
    auto begin();
brief

Returns an iterator to the beginning.


end

signature
    auto end();
brief

Returns an iterator to the end.


cbegin

signature
    auto cbegin() const;
brief

Returns a constant iterator to the beginning.


cend

signature
    auto cend() const;
brief

Returns a constant iterator to the end.


rbegin

signature
    auto rbegin();
brief

Returns a reverse iterator to the beginning.


rend

signature
    auto rend();
brief

Returns a reverse iterator to the end.


crebegin

signature
    auto crbegin() const;
brief

Returns a constant reverse iterator to the beginning.


crend

signature
    auto crend() const;
brief

Returns a constant reverse iterator to the end.


Get/Set functions

layout

signature
    const Layout<N>& layout();
brief

Get the Layout used by the Holor to map indices to memory locations.

return

a Layout.


HolorRef

lengths

signature
  1.     auto lengths() const;
    
  2.     auto lengths(size_t dim) const;
    
brief

Get the lengths, i.e., the number of elements that the container has per each dimension.

parameters
  • dim: request to get only the lenght for the dim dimension. There is no check on the validity of this argument.
return

When called without arguments, the function returns a std::array with the lenght of all dimensions ofthe container. When the argument dim is passed, the function returns a single legnth (a size_t).


size

signature
    size_t size() const;
brief

Get the total number of elements in the container.

return

Return the number of elements in the container, a size_t.


data

signature
  1.     T* data();
    
  2.     const T* data();
    
brief

Get a flat access to the memory that stores the elements contained in the container.

return

A pointer to the memory location where the elements are stored.


Indexing functions

operator()

signature
  1.     template<SingleIndex... Dims> requires ((sizeof...(Dims)==N) )
        T& operator()(Dims&&... dims);
    
  2.     template<SingleIndex... Dims> requires ((sizeof...(Dims)==N) )
        const T operator()(Dims&&... dims) const;
    
  3.     template <class Container> requires ((assert::SizedContainer<Container, N> || assert::ResizeableContainer<Container>) && SingleIndex<typename Container::value_type>)
        T& operator()(const Container& indices);
    
  4.     template <class Container> requires ((assert::SizedContainer<Container, N> || assert::ResizeableContainer<Container>) && SingleIndex<typename Container::value_type>)
        const T access(const Container& indices) const;
    
brief

Access a single element in the container.

parameters
  • dims: pack of indices, one per dimension of the Holor container, given either as a parameter pack or as an array of SingleIndex elements (Refer to Indices for more details).
  • indices: container of SingleIndex elements (e.g. a std::vector or a std::array).

Warning

When indexing a Holor, the conversion from indices to a memory location performed by the Layout may throw an holor::exception::HolorRuntimeError if the arguments are outside the admissible range for each coordinate of the Layout. The compiler flag DDEFINE_ASSERT_LEVEL in the CMakeLists can be set to AssertionLevel::no_checks to exclude this check. Refer to Exceptions for more details.

return

The element in the Holor at the selected coordinates.


Slicing functions

operator()

signature
    template<typename... Args> requires (impl::ranged_index_pack<Args...>() && (sizeof...(Args)==N) )
    auto operator()(Args&&... args);
brief

Access a slice of the container.

parameters
  • args: parameters pack. Each element of the pack must be either a SingleIndex or a RangeIndex, and at least one of them must be a RangeIndex. Refer to Indices for more details.

Warning

When slicing a Holor, the conversion from indices to a memory location performed by the Layout may throw an holor::exception::HolorRuntimeError if the arguments are outside the admissible range for each coordinate of the Layout. The compiler flag DDEFINE_ASSERT_LEVEL in the CMakeLists can be set to AssertionLevel::no_checks to exclude this check. Refer to Exceptions for more details.

return

A slice as a HolorRef. The number of dimensions of the returned holorRef depends on the input arguments, as each SingleIndex passed in the parameters pack collapses one dimension.


row

signature
  1.     auto row(size_t i);
    
  2.     const auto row(size_t i) const;
    
brief

Get a single row of the container.

parameters
  • i: selects the i-th row.

Warning

When slicing a row of the Holor an holor::exception::HolorRuntimeError exception maybe thrown if the arguments are outside the admissible range for each coordinate of the Layout. The compiler flag DDEFINE_ASSERT_LEVEL in the CMakeLists can be set to AssertionLevel::no_checks to exclude this check. Refer to Exceptions for more details.

return

the slice corresponding to the i-th row. This slice is a HolorRef with N-1 dimensions.


Warning

Since the slice has N-1 dimensions, this function is available only for Holor containers with N>1.

col

signature
  1.     HolorRef<T, N-1> col(size_t i);
    
  2.     const HolorRef<T, N-1> col(size_t i) const;
    
brief

Get a single column of the container.

parameters
  • i: selects the i-th column.

Warning

When slicing a column of the Holor an holor::exception::HolorRuntimeError exception maybe thrown if the arguments are outside the admissible range for each coordinate of the Layout. The compiler flag DDEFINE_ASSERT_LEVEL in the CMakeLists can be set to AssertionLevel::no_checks to exclude this check. Refer to Exceptions for more details.

return

The slice corresponding to the i-th column. This slice is a HolorRef with N-1 dimensions.


Warning

Since the slice has N-1 dimensions, this function is available only for Holor containers with N>1.

slice

signature
  1.     template<size_t M> requires (M<N)
        auto slice(size_t i);
    
  2.     template<size_t M> requires (M<N)
        const auto slice(size_t i) const;
    
  3.     template<size_t M> requires (M<N)
        auto slice(range range_slice)
    
  4.     template<size_t M> requires (M<N)
        const auto slice(range range_slice) const;
    
brief

Slice the HolorRef along the M-th dimension.

template parameters
  • M is the dimension to be sliced. 0 is a row, 1 is a column, ...
parameters
  • i is the index of a single component to be taken along the M-th dimension.
  • range_slice is a range of indices to be taken along the M-th dimension.

Warning

When slicing a dimension of the HolorRef an holor::exception::HolorRuntimeError exception maybe thrown if the arguments are outside the admissible range for each coordinate of the Layout. The compiler flag DDEFINE_ASSERT_LEVEL in the CMakeLists can be set to AssertionLevel::no_checks to exclude this check. Refer to Exceptions for more details.

return

A HolorRef to the slice taken along the M-th dimension. This slice is a HolorRef with N-1 dimensions if it is indexed with a single index i (1-2), and a a HolorRef with N dimensions if it is indexed with a range of indices range_slice (3-4).

Warning

This function is available only for Holor containers with N>1. Moreover, it must be M<N.

Non-Member functions

equality operator==

signature
  1.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator==(const HolorRef<T,N>& h1, const HolorRef<T,N>& h2);
    
  2.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator==(const HolorRef<T,N>& h1, const Holor<T,N>& h2);
    
  3.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator==(const Holor<T,N>& h1, const HolorRef<T,N>& h2);
    
brief

Comparison operator that verifies the equality of two HolorLib containers with the same dimension N and type of elements T.

Note

Two HolorRef containers or a HolorRef and a Holor container are considered equal if they have the same lengths and contain the same elements (but their layouts may be different).

template parameter
  • N: the dimension of the two container to be compared.
  • T: the type of the elements in the container.
parameter
  • h1: left hand side of the comparison.
  • h2: right hand side of the comparison.
return

true if the two containers are equal, false otherwise


inequality operator!=

signature
  1.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator!=(const HolorRef<T,N>& h1, const HolorRef<T,N>& h2);
    
  2.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator!=(const HolorRef<T,N>& h1, const Holor<T,N>& h2);
    
  3.     template<typename T, size_t N> requires std::equality_comparable<T>
        bool operator!=(const Holor<T,N>& h1, const HolorRef<T,N>& h2);
    
brief

Comparison operator that verifies the inequality of two HolorLib containers with the same dimension N and type of elements T.

Note

Two HolorRef containers or a HolorRef and a Holor container are considered equal if they have the same lengths and contain the same elements (but their layouts may be different).

template parameter
  • N: the dimension of the two container to be compared.
  • T: the type of the elements in the container.
parameter
  • h1: left hand side of the comparison.
  • h2: right hand side of the comparison.
return

true if the two containers are not equal, false otherwise.

Back to top