Skip to content

Commit

Permalink
Customize swap for projection references
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 18, 2023
1 parent afad903 commit 6496153
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/llama/mapping/Projection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ namespace llama::mapping
LLAMA_END_SUPPRESS_HOST_DEVICE_WARNING
return *this;
}

LLAMA_FN_HOST_ACC_INLINE friend void swap(ProjectionReference a, ProjectionReference b) noexcept
{
const auto va = static_cast<value_type>(a);
const auto vb = static_cast<value_type>(b);
a = vb;
b = va;
}
};
} // namespace internal

Expand Down
16 changes: 16 additions & 0 deletions tests/mapping.Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ TEST_CASE("mapping.Projection.AoS.DoubleToFloat")
iotaCheckView(view);
}

TEST_CASE("mapping.Projection.swap")
{
auto mapping = llama::mapping::Projection<
llama::ArrayExtents<int, 2>,
double,
llama::mapping::BindAoS<>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<double, DoubleToFloat>>>{{}};

auto view = llama::allocView(mapping);
view(0) = 1.0;
view(1) = 2.0;
swap(view(0), view(1));
CHECK(view(0) == 2.0);
CHECK(view(1) == 1.0);
}

namespace
{
struct Sqrt
Expand Down

0 comments on commit 6496153

Please sign in to comment.