Skip to content

Commit

Permalink
Support RecordRef::at<"str">()
Browse files Browse the repository at this point in the history
This adds an alternative access syntax when record dimension reflection is available.
  • Loading branch information
bernhardmgruber committed Aug 1, 2023
1 parent d65fee7 commit a3de119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/llama/RecordRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,25 @@ namespace llama
return operator()(RecordCoord{});
}

#ifdef LLAMA_HAS_STRING_FIELDS
/// Experimental
template<internal::FixedString Name>
LLAMA_FN_HOST_ACC_INLINE auto at() const -> decltype(auto)
{
using RecordCoord = GetCoordFromTags<AccessibleRecordDim, internal::StringTag<Name>>;
return operator()(RecordCoord{});
}

// FIXME(bgruber): remove redundancy
/// Experimental
template<internal::FixedString Name>
LLAMA_FN_HOST_ACC_INLINE auto at() -> decltype(auto)
{
using RecordCoord = GetCoordFromTags<AccessibleRecordDim, internal::StringTag<Name>>;
return operator()(RecordCoord{});
}
#endif

template<typename T>
LLAMA_FN_HOST_ACC_INLINE auto operator=(const T& other) -> RecordRef&
{
Expand Down
10 changes: 10 additions & 0 deletions tests/recorddimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ TEST_CASE("recorddim.Boost.Describe")
CHECK(view(0)(llama::RecordCoord<1>{}) == 2);
CHECK(view(0)(llama::RecordCoord<2, 0>{}) == 3);
CHECK(view(0)(llama::RecordCoord<2, 1>{}) == 4);

view(0).at<"a">() = 5;
view(0).at<"b">() = 6;
view(0).at<"pos">().at<"x">() = 7;
view(0).at<"pos">().at<"y">() = 8;

CHECK(view(0)(llama::RecordCoord<0>{}) == 5);
CHECK(view(0)(llama::RecordCoord<1>{}) == 6);
CHECK(view(0)(llama::RecordCoord<2, 0>{}) == 7);
CHECK(view(0)(llama::RecordCoord<2, 1>{}) == 8);
}
#endif

Expand Down

0 comments on commit a3de119

Please sign in to comment.