-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
I would expect this test case to pass:
TEST_CASE("issue 67") {
int i = 42;
int j = 43;
tl::optional<std::reference_wrapper<int>> a = std::ref(i);
REQUIRE(&a.value().get() == &i);
a = std::ref(j);
REQUIRE(&a.value().get() == &j);
tl::optional<int&> b = std::ref(i);
REQUIRE(&b.value() == &i);
b = std::ref(j);
REQUIRE(&b.value() == &j);
}
Instead, it currently fails to compile:
tl-optional/include/tl/optional.hpp:1942:41: error: cannot initialize a member subobject of type 'int *' with an rvalue of type 'std::reference_wrapper<int> *'
constexpr optional(U &&u) noexcept : m_value(std::addressof(u)) {
^ ~~~~~~~~~~~~~~~~~
tl-optional/tests/issues.cpp:55:28: note: in instantiation of function template specialization 'tl::optional<int &>::optional<std::reference_wrapper<int>, nullptr>' requested here
tl::optional<int&> b = std::ref(i);
^
Furthermore, I'd like the following to compile too:
tl::optional<int&> c = a;
REQUIRE(&c.value() == &j);
c = tl::optional<std::reference_wrapper<int>>(std::ref(i));
REQUIRE(&c.value() == &i);
But that requires solving issue #66 first.
Metadata
Metadata
Assignees
Labels
No labels