diff --git a/include/llama/View.hpp b/include/llama/View.hpp index 4717b9e027..1998829131 100644 --- a/include/llama/View.hpp +++ b/include/llama/View.hpp @@ -98,34 +98,29 @@ namespace llama typename Mapping::ArrayExtents::Index ai, RecordCoord rc) { - using FieldType = GetType; - - // this handles physical and computed mappings - if constexpr(sizeof...(RCs) == 0) + auto init = [](auto&& ref) LLAMA_LAMBDA_INLINE { - using RefType = decltype(view(ai)); - if constexpr(isProxyReference) + using FieldType = GetType>; + using RefType = decltype(ref); + if constexpr(isProxyReference>) { - view(ai) = FieldType{}; + ref = FieldType{}; } else if constexpr( std::is_lvalue_reference_v && !std::is_const_v>) { - new(&view(ai)) FieldType{}; + new(&ref) FieldType{}; } + }; + + // this handles physical and computed mappings + if constexpr(sizeof...(RCs) == 0) + { + init(view(ai)); } else { - using RefType = decltype(view(ai)(rc)); - if constexpr(isProxyReference) - { - view(ai)(rc) = FieldType{}; - } - else if constexpr( - std::is_lvalue_reference_v && !std::is_const_v>) - { - new(&view(ai)(rc)) FieldType{}; - } + init(view(ai)(rc)); } }