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¶
HolorRef();HolorRef(const HolorRef<T, N>& holor_ref);HolorRef(HolorRef<T, N>&& holor_ref);HolorRef(T* dataptr, const Layout<N>& layout);template <class Container> requires assert::SizedTypedContainer<Container, size_t, N> explicit HolorRef(T* dataptr, const Container& lengths);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. astd::array) or as a dynamic size container (e.g., astd::vector).
return¶
A HolorRef container.
Assignments¶
signature¶
HolorRef& operator=(HolorRef<T, N>&& holor_ref);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¶
auto lengths() const;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 thedimdimension. 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¶
T* data();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¶
template<SingleIndex... Dims> requires ((sizeof...(Dims)==N) ) T& operator()(Dims&&... dims);template<SingleIndex... Dims> requires ((sizeof...(Dims)==N) ) const T operator()(Dims&&... dims) const;template <class Container> requires ((assert::SizedContainer<Container, N> || assert::ResizeableContainer<Container>) && SingleIndex<typename Container::value_type>) T& operator()(const Container& indices);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 ofSingleIndexelements (Refer to Indices for more details).indices: container ofSingleIndexelements (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 aSingleIndexor aRangeIndex, and at least one of them must be aRangeIndex. 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¶
auto row(size_t i);const auto row(size_t i) const;
brief¶
Get a single row of the container.
parameters¶
i: selects thei-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¶
HolorRef<T, N-1> col(size_t i);const HolorRef<T, N-1> col(size_t i) const;
brief¶
Get a single column of the container.
parameters¶
i: selects thei-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¶
template<size_t M> requires (M<N) auto slice(size_t i);template<size_t M> requires (M<N) const auto slice(size_t i) const;template<size_t M> requires (M<N) auto slice(range range_slice)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¶
Mis the dimension to be sliced. 0 is a row, 1 is a column, ...
parameters¶
iis the index of a single component to be taken along theM-th dimension.range_sliceis a range of indices to be taken along theM-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¶
template<typename T, size_t N> requires std::equality_comparable<T> bool operator==(const HolorRef<T,N>& h1, const HolorRef<T,N>& h2);template<typename T, size_t N> requires std::equality_comparable<T> bool operator==(const HolorRef<T,N>& h1, const Holor<T,N>& h2);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¶
template<typename T, size_t N> requires std::equality_comparable<T> bool operator!=(const HolorRef<T,N>& h1, const HolorRef<T,N>& h2);template<typename T, size_t N> requires std::equality_comparable<T> bool operator!=(const HolorRef<T,N>& h1, const Holor<T,N>& h2);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.