mirror of
https://github.com/TartanLlama/optional.git
synced 2025-08-03 20:04:26 +02:00
'optional<T&>::and_then(F&& f) &&' calls f with lvalue reference
This makes sense. The 'optional' is an rvalue, but its contained type remains an lvalue reference. I.e. int i = 3; optional<int&>{i}.and_then([](int& r){return optional<int&>{++r}); The optional r-value still refers to 'i', which is not an r-value.
This commit is contained in:
@@ -237,9 +237,14 @@ TEST_CASE("Monadic operations", "[monadic]") {
|
||||
REQUIRE(!o18r);
|
||||
|
||||
const tl::optional<int> o19 = tl::nullopt;
|
||||
auto o19r =
|
||||
std::move(o19).and_then([](int i) { return tl::make_optional(42); });
|
||||
auto o19r = std::move(o19).and_then([](int i) { return tl::make_optional(42); });
|
||||
REQUIRE(!o19r);
|
||||
|
||||
int i = 3;
|
||||
tl::optional<int&> o20{i};
|
||||
std::move(o20).and_then([](int& r){return tl::optional<int&>{++r};});
|
||||
REQUIRE(o20);
|
||||
REQUIRE(i == 4);
|
||||
}
|
||||
|
||||
SECTION("constexpr and_then") {
|
||||
|
Reference in New Issue
Block a user