diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index e9c59c2..945787a 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -1936,11 +1936,10 @@ template class optional { TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default; /// Constructs the stored value with `u`. - template >::value> + template ::value> * = nullptr> - constexpr optional(U &&u) noexcept : m_value(std::addressof(u)) { - static_assert(std::is_lvalue_reference::value, "U must be an lvalue"); + constexpr optional(U &&u) noexcept : m_value(std::addressof(static_cast(u))) { } template @@ -1964,12 +1963,11 @@ template class optional { optional &operator=(const optional &rhs) = default; /// Rebinds this optional to `u`. - template >::value> + template ::value> * = nullptr> optional &operator=(U &&u) { - static_assert(std::is_lvalue_reference::value, "U must be an lvalue"); - m_value = std::addressof(u); + m_value = std::addressof(static_cast(u)); return *this; } diff --git a/tests/issues.cpp b/tests/issues.cpp index 85b7c6e..5ec5602 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -43,3 +43,17 @@ TEST_CASE("issue 33") { REQUIRE(*a == 42); REQUIRE(a.has_value()); } + +TEST_CASE("issue 66") { + int i = 42; + int j = 43; + tl::optional> a = std::ref(i); + REQUIRE(&a.value().get() == &i); + a = std::ref(j); + REQUIRE(&a.value().get() == &j); + + tl::optional b = std::ref(i); + REQUIRE(&b.value() == &i); + b = std::ref(j); + REQUIRE(&b.value() == &j); +}