Skip to content

Commit 89a2cc8

Browse files
committed
working on -> for ref
1 parent 201b2f1 commit 89a2cc8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

include/libfork/ev.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class ev<T> : detail::immovable<ev<T>> {
6969
[[nodiscard]] constexpr auto operator->(this Self &self)
7070
LF_HOF_RETURNS(std::addressof(self.m_value))
7171

72+
// TODO: support oprator->() for this&& self param
73+
74+
// [[nodiscard]] constexpr auto operator->() noexcept -> T * { return std::addressof(m_value); }
75+
// [[nodiscard]] constexpr auto operator->() const noexcept -> T * {
76+
// return std::addressof(m_value);
77+
// }
78+
7279
private:
7380
constexpr auto get() & -> T * { return std::addressof(m_value); }
7481

@@ -87,6 +94,14 @@ class ev<T> {
8794
return std::forward_like<Self>(*self.m_ptr);
8895
}
8996

97+
[[nodiscard]] constexpr auto operator->() noexcept -> std::remove_reference_t<T> * {
98+
return m_ptr;
99+
}
100+
101+
[[nodiscard]] constexpr auto operator->() const noexcept -> std::remove_reference_t<T> const * {
102+
return m_ptr;
103+
}
104+
90105
private:
91106
std::add_pointer_t<std::remove_reference_t<T>> m_ptr;
92107
};

test/src/test_ev.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ TEMPLATE_TEST_CASE("Ev operator *", "[ev]", nt, int, int &, int &&, int const &,
5151
static_assert(std::same_as<decltype(*std::move(cval)), U const &&>);
5252
}
5353

54-
TEMPLATE_TEST_CASE("Eventually operator ->", "[ev]", nt, int) {
54+
TEMPLATE_TEST_CASE("Eventually operator ->", "[ev]", nt, int, int &) {
55+
56+
using U = std::remove_reference_t<TestType>;
5557

5658
lf::ev<TestType> val{};
57-
static_assert(std::same_as<decltype(val.operator->()), TestType *>);
59+
static_assert(std::same_as<decltype(val.operator->()), U *>);
5860

5961
lf::ev<TestType> const cval{};
60-
static_assert(std::same_as<decltype(cval.operator->()), TestType const *>);
62+
static_assert(std::same_as<decltype(cval.operator->()), U const *>);
6163
}

0 commit comments

Comments
 (0)