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 cb2b150
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 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));
using FieldType = GetType<typename Mapping::RecordDim, RecordCoord<RCs...>>;
using RefType = decltype(ref);
if constexpr(isProxyReference<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 cb2b150

Please sign in to comment.