From 1158bc2a770c0b7e04462ca7e2a9cf5bb8de7a36 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Wed, 14 Sep 2022 12:46:09 +0200 Subject: [PATCH] Refactor asTupleImpl and asFlatTupleImpl This should improve readability and make the return type more clearly visible. --- include/llama/RecordRef.hpp | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/include/llama/RecordRef.hpp b/include/llama/RecordRef.hpp index 98986bc34e..9aa7982afa 100644 --- a/include/llama/RecordRef.hpp +++ b/include/llama/RecordRef.hpp @@ -195,22 +195,27 @@ namespace llama } }; - template - LLAMA_FN_HOST_ACC_INLINE auto asTupleImpl(ProxyReference&& leaf, T) - -> std::enable_if_t>, ProxyReference> + template< + typename ProxyReference, + typename T, + std::enable_if_t>, int> = 0> + LLAMA_FN_HOST_ACC_INLINE auto asTupleImpl(ProxyReference&& leaf, T) -> ProxyReference { return leaf; } - template - LLAMA_FN_HOST_ACC_INLINE auto asTupleImpl(TWithOptionalConst& leaf, T) -> std:: - enable_if_t>, std::reference_wrapper> + template< + typename TWithOptionalConst, + typename T, + std::enable_if_t>, int> = 0> + LLAMA_FN_HOST_ACC_INLINE auto asTupleImpl(TWithOptionalConst& leaf, T) + -> std::reference_wrapper { return leaf; } template - LLAMA_FN_HOST_ACC_INLINE auto asTupleImplArr(RecordRef&& vd, T (&&)[N], std::index_sequence) + LLAMA_FN_HOST_ACC_INLINE auto asTupleImplForArray(RecordRef&& vd, T (&&)[N], std::index_sequence) { return std::make_tuple(asTupleImpl(vd(RecordCoord{}), T{})...); } @@ -218,7 +223,7 @@ namespace llama template LLAMA_FN_HOST_ACC_INLINE auto asTupleImpl(RecordRef&& vd, T (&&a)[N]) { - return asTupleImplArr(std::forward(vd), std::move(a), std::make_index_sequence{}); + return asTupleImplForArray(std::forward(vd), std::move(a), std::make_index_sequence{}); } template @@ -227,22 +232,27 @@ namespace llama return std::make_tuple(asTupleImpl(vd(GetFieldTag{}), GetFieldType{})...); } - template - LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImpl(ProxyReference&& leaf, T) - -> std::enable_if_t>, std::tuple> + template< + typename ProxyReference, + typename T, + std::enable_if_t>, int> = 0> + LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImpl(ProxyReference&& leaf, T) -> std::tuple { - return {std::move(leaf)}; + static_assert(!std::is_reference_v); + return {std::move(leaf)}; // NOLINT(bugprone-move-forwarding-reference) } - template - LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImpl(TWithOptionalConst& leaf, T) - -> std::enable_if_t>, std::tuple> + template< + typename TWithOptionalConst, + typename T, + std::enable_if_t>, int> = 0> + LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImpl(TWithOptionalConst& leaf, T) -> std::tuple { return {leaf}; } template - LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImplArr(RecordRef&& vd, T (&&)[N], std::index_sequence) + LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImplForArray(RecordRef&& vd, T (&&)[N], std::index_sequence) { return std::tuple_cat(asFlatTupleImpl(vd(RecordCoord{}), T{})...); } @@ -250,7 +260,7 @@ namespace llama template LLAMA_FN_HOST_ACC_INLINE auto asFlatTupleImpl(RecordRef&& vd, T (&&a)[N]) { - return asFlatTupleImplArr(std::forward(vd), std::move(a), std::make_index_sequence{}); + return asFlatTupleImplForArray(std::forward(vd), std::move(a), std::make_index_sequence{}); } template @@ -302,7 +312,7 @@ namespace llama LLAMA_FN_HOST_ACC_INLINE auto makeFromTuple(Tuple&& src, std::index_sequence) { using std::get; - return T{get(std::forward(src))...}; + return T{get(src)...}; // no forward of src, since we call get multiple times on it } template