Reference documentation for deal.II version 9.3.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Typedefs
ndarray.h File Reference
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <array>

Go to the source code of this file.

Typedefs

template<typename T , std::size_t... Ns>
using ndarray = typename internal::ndarray::HelperArray< T, Ns... >::type
 

Typedef Documentation

◆ ndarray

template<typename T , std::size_t... Ns>
using ndarray = typename internal::ndarray::HelperArray<T, Ns...>::type

A (variadic template) type alias for conveniently defining multidimensional std::arrays

The problem we try to address with the type alias is the following. Suppose you want to create a multdimensional array of doubles of, for example, rank 3, with sizes 2, 3, 4 for the first, middle, and last index. Then using C-style arrays you could simply write

double my_array[2][3][4] = { ... };

Nowadays, there are a number of good reasons why using C-style arrays is usually discouraged (ranging from incompatibilities with STL functions requiring awkward wrappers, surprises when comparing for equality, etc.) If you want to do the same, however, using the more modern (and encouraged) std::array class, then you would have to declare

std::array<std::array<std::array<double, 4>, 3>, 2> = { ... };

The repetitions of std::array look awkward and, worse, the index ranges have reversed: the leftmost index has range [0,2), the middle index has range [0,3) and the rightmost index has range [0,4). We address this issue by providing a class ndarray that allows to you declare the above stacked std::array type by simply writing:

::ndarray<double, 2, 3, 4> my_array = { ... };
Note
ndarray is merely syntactic sugar in form of a type alias (using declaration). It is not a deal.II specific class, but merely a helper to cleanly define multidimensional arrays realized by "stacked" std::array classes.

Definition at line 108 of file ndarray.h.