Skip to content

Commit

Permalink
Add structured binding support to GpuTuple (AMReX-Codes#3977)
Browse files Browse the repository at this point in the history
## Summary

This PR adds C++17 structured binding support to `amrex::GpuTuple`.

## Additional background

See case 2
in https://en.cppreference.com/w/cpp/language/structured_binding.
Note that structured bindings will also use the existing `amrex::get`.
  • Loading branch information
AlexanderSinn authored Jun 8, 2024
1 parent 61b2965 commit 0da4d8b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Src/Base/AMReX_Tuple.H
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,23 @@ auto tupleToArray (GpuTuple<T,Ts...> const& tup)
return detail::tuple_to_array_helper(tup, std::index_sequence_for<T,Ts...>{});
}

}
} // namespace amrex

// Spcialize std::tuple_size for GpuTuple. Used by structured bindings.
template<typename... Ts>
struct std::tuple_size<amrex::GpuTuple<Ts...>> {
static constexpr std::size_t value = sizeof...(Ts);
};

// Spcialize std::tuple_element for GpuTuple. Used by structured bindings.
template<typename T, typename... Ts>
struct std::tuple_element<std::size_t{0}, amrex::GpuTuple<T, Ts...>> {
using type = T;
};

template<std::size_t s, typename T, typename... Ts>
struct std::tuple_element<s, amrex::GpuTuple<T, Ts...>> {
using type = typename std::tuple_element<s-1, amrex::GpuTuple<Ts...>>::type;
};

#endif /*AMREX_TUPLE_H_*/

0 comments on commit 0da4d8b

Please sign in to comment.