From 0da4d8b7e65710a93f7ea1509d3c183ee0df1453 Mon Sep 17 00:00:00 2001 From: Alexander Sinn <64009254+AlexanderSinn@users.noreply.github.com> Date: Sat, 8 Jun 2024 23:43:47 +0200 Subject: [PATCH] =?UTF-8?q?Add=20structured=20binding=20support=20to=C2=A0?= =?UTF-8?q?GpuTuple=20(#3977)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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`. --- Src/Base/AMReX_Tuple.H | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Src/Base/AMReX_Tuple.H b/Src/Base/AMReX_Tuple.H index a628a5e30de..4d74198272f 100644 --- a/Src/Base/AMReX_Tuple.H +++ b/Src/Base/AMReX_Tuple.H @@ -416,6 +416,23 @@ auto tupleToArray (GpuTuple const& tup) return detail::tuple_to_array_helper(tup, std::index_sequence_for{}); } -} +} // namespace amrex + +// Spcialize std::tuple_size for GpuTuple. Used by structured bindings. +template +struct std::tuple_size> { + static constexpr std::size_t value = sizeof...(Ts); +}; + +// Spcialize std::tuple_element for GpuTuple. Used by structured bindings. +template +struct std::tuple_element> { + using type = T; +}; + +template +struct std::tuple_element> { + using type = typename std::tuple_element>::type; +}; #endif /*AMREX_TUPLE_H_*/