Skip to content

Commit

Permalink
remove invalid get overload for blade types (#58)
Browse files Browse the repository at this point in the history
`get` should not be invocable for `blade` types. The ratio function of
exercise 2.12.1 is updated to obtain the `coefficient` of each `blade`
parameter.

This commit partially reverts 8b5b03b.

Change-Id: Ibe893d2a7a6ccc692a21522fa1f27e055023b042
  • Loading branch information
oliverlee committed Jun 10, 2024
1 parent a1a8f1c commit 1ead3bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
12 changes: 5 additions & 7 deletions exercises/2.12.1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ constexpr auto e1 = e<1>;
constexpr auto e2 = e<2>;
constexpr auto e3 = e<3>;

template <class B1, class B2>
template <class B>
[[nodiscard]]
constexpr auto ratio(B1 b1, B2 b2)
constexpr auto ratio(B b1, B b2)
{
static_assert(::geometry::is_blade_v<B2>);
static_assert(::geometry::is_blade_v<B>);

const auto a1 = ::geometry::get<B2>(b1);
const auto a2 = ::geometry::get<B2>(b2);

assert(b1 == ((a1 / a2) * b2));
const auto a1 = b1.coefficient;
const auto a2 = b2.coefficient;

return a1 / a2;
}
Expand Down
11 changes: 1 addition & 10 deletions geometry/src/get.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@ struct get_fn
template <
class V,
class D = std::decay_t<V>,
std::enable_if_t<is_multivector_v<D> and D::template contains<B>, bool> =
true>
class = std::enable_if_t<is_multivector_v<D> and D::template contains<B>>>
constexpr decltype(auto) operator()(V && v) const
{
return get<B>(std::forward<V>(v));
}
template <
class V,
class D = std::decay_t<V>,
std::enable_if_t<is_blade_v<D> and std::is_same_v<B, D>, bool> = true>
constexpr decltype(auto) operator()(V && v) const
{
return std::forward<V>(v).coefficient;
}
};

} // namespace detail
Expand Down
15 changes: 1 addition & 14 deletions test/algebra_get_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,12 @@ auto main() -> int
return expect(true);
};

"get used with blade"_ctest = [] {
"get not used with multivector"_ctest = [] {
const auto b = e<1>;

using geometry::get;
auto f = [](auto x) -> decltype(get<blade<1>>(x)) {};

static_assert(std::is_invocable_v<decltype(f), decltype(b)>);
static_assert(
std::is_invocable_v<decltype(::geometry::get<blade<1>>), decltype(b)>);

return expect(true);
};

"get used with wrong blade"_ctest = [] {
const auto b = e<2>;

using geometry::get;
auto f = [](auto x) -> decltype(get<blade<1>>(x)) {};

static_assert(not std::is_invocable_v<decltype(f), decltype(b)>);
static_assert(
not std::
Expand Down

0 comments on commit 1ead3bf

Please sign in to comment.