atlas
atlas copied to clipboard
Added function to create `std::variant` for multiple array views.
During PR #218, I found myself writing two nested switch statements in order to create an ArrayView
from an Array
. I've found myself writing this same pattern multiple times throughout Atlas, and indeed other external applications which use atlas.
This PR adds provides an alternative to the nested switch statement. The method util::make_array_view_variant<Values<types...>, Ranks<ints...>>(Array& array)
creates an std::variant
of ArrayView
types, and then assigns the view that matches array
(so long as the value-type and rank can be found within the Values
and Ranks
arguments respectively. The ArrayView
can then be accessed rather succinctly using std::visit
.