Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot deal with reference_wrapper #67

Open
Quuxplusone opened this issue Sep 8, 2024 · 0 comments · May be fixed by #68
Open

Cannot deal with reference_wrapper #67

Quuxplusone opened this issue Sep 8, 2024 · 0 comments · May be fixed by #68

Comments

@Quuxplusone
Copy link

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.

Quuxplusone added a commit to Quuxplusone/tl-optional that referenced this issue Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant