Skip to content

Commit

Permalink
Refactor constructField
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 21, 2024
1 parent c7d9806 commit 3c73b92
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,29 @@ namespace llama
typename Mapping::ArrayExtents::Index ai,
RecordCoord<RCs...> rc)
{
using FieldType = GetType<typename Mapping::RecordDim, decltype(rc)>;

// 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<RefType>)
using FieldType = GetType<typename Mapping::RecordDim, RecordCoord<RCs...>>;
using RefType = decltype(ref);
if constexpr(isProxyReference<std::remove_reference_t<RefType>>)
{
view(ai) = FieldType{};
ref = FieldType{};
}
else if constexpr(
std::is_lvalue_reference_v<RefType> && !std::is_const_v<std::remove_reference_t<RefType>>)
{
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<RefType>)
{
view(ai)(rc) = FieldType{};
}
else if constexpr(
std::is_lvalue_reference_v<RefType> && !std::is_const_v<std::remove_reference_t<RefType>>)
{
new(&view(ai)(rc)) FieldType{};
}
init(view(ai)(rc));
}
}

Expand Down

0 comments on commit 3c73b92

Please sign in to comment.