template<class TContainer, class Extents, class LayoutPolicy = layout_right>
class gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >
Multidimensional array that manages its own memory.
- Note
- No bounds checking when accessing memory
-
That the view holds a valid pointer to the data is a class invariant.
The Container type that stores the data may be resizable (std::vector or similar) or static (std::array or similar). Copy and move assignment routines as well as swapping are designed to yield good performances in both cases, notably foregoing the copy-swap idiom due to the bad performance in swapping std::array.
This class avoids throwing exceptions, apart from the ones that might be thrown from the containers during resizing an allocation. (bad_malloc from std::vector is a likely candidate)
Holds as many elements as required by a multidimensional view.
- Template Parameters
-
TContainer | Data type container for the data to be stored as MultiDimArray with random element access and value_type, reference and const_reference exposed |
Extents | An extents class describing the array dimensions as used in module_mdspan |
LayoutPolicy | The data layout as in module_mdspan describes translation of indices to memory offset. Defaults to right aligned, so that the right-most index is contiguous in memory. |
|
template<class... IndexType, typename T = TContainer, typename = typename std::enable_if_t<detail::is_resizable_v<T>>> |
| MultiDimArray (IndexType...dynamicExtent) |
| Allocate dynamic array data and set view with the dynamic extents. More...
|
|
template<typename T = TContainer, typename = typename std::enable_if_t<!detail::is_resizable_v<T>>> |
constexpr | MultiDimArray (const TContainer &data={}) noexcept |
| Construction from fixed sized arrays if the array size is static and layout policy allows compile time determination of the container size. More...
|
|
constexpr | MultiDimArray (const MultiDimArray &o) |
| Copy constructor.
|
|
| MultiDimArray (MultiDimArray &&o) noexcept |
| Move constructor.
|
|
MultiDimArray & | operator= (const MultiDimArray &o) |
| Copy assignment.
|
|
MultiDimArray & | operator= (MultiDimArray &&o) noexcept |
| Move assignment.
|
|
void | swap (MultiDimArray &o) noexcept |
| Swaps content with other.
|
|
template<class... IndexType> |
void | resize (IndexType...dynamicExtent) |
| Resize the dynamic extents of the array if any and set container size accordingly. More...
|
|
template<class... IndexType> |
reference | operator() (IndexType...index) noexcept |
| Data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R) More...
|
|
template<class... IndexType> |
constexpr const_reference | operator() (IndexType...index) const noexcept |
| Const data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R) More...
|
|
ArrayRef< value_type > | toArrayRef () |
| Contiguous access to the data. More...
|
|
constexpr ArrayRef< const
value_type > | toArrayRef () const |
| Contiguous const access to the data. More...
|
|
constexpr view_type::index_type | extent (int k) const noexcept |
| Return the extent. More...
|
|
constexpr view_type | asView () noexcept |
| Conversion to multidimensional view on the data.
|
|
constexpr const_view_type | asConstView () const noexcept |
| Conversion to const multidimensional view on the data.
|
|
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType, typename T = TContainer, typename = typename std::enable_if_t<detail::is_resizable_v<T>>>
Allocate dynamic array data and set view with the dynamic extents.
- Parameters
-
[in] | dynamicExtent | A parameter pack that describes the dynamic size of the array. Empty if purely static. |
- Template Parameters
-
IndexType | Parameter pack type holding the dynamic extents of the multidimensional array |
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<typename T = TContainer, typename = typename std::enable_if_t<!detail::is_resizable_v<T>>>
Construction from fixed sized arrays if the array size is static and layout policy allows compile time determination of the container size.
Enables the expected initialization MultiDimArray<std::array<float, 9>, extents<3,3>> arr = {{1,2...}}
- Template Parameters
-
T | Template parameter for activation via SFINAE. |
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
Data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R)
- Parameters
-
[in] | index | multidimensional indices as parameter pack the number of parameters must match the rank of the array. |
- Returns
- reference to array element
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
Const data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R)
- Parameters
-
[in] | index | multidimensional indices as parameter pack the number of parameters must match the rank of the array. |
- Returns
- const reference to array element
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
void gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::resize |
( |
IndexType... |
dynamicExtent | ) |
|
|
inline |
Resize the dynamic extents of the array if any and set container size accordingly.
Invalidates data and views of this array.
- Parameters
-
[in] | dynamicExtent | A parameter pack that describes the dynamic size of the array. Empty if purely static. |
- Template Parameters
-
IndexType | Parameter pack type holding the dynamic extents of the multidimensional array |