This commit is contained in:
Simon Brand
2018-09-03 09:09:47 +01:00
parent 8b1c3fb67f
commit aecb8fe6db
3 changed files with 23 additions and 3 deletions

19
tests/issues.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "catch.hpp"
#include "optional.hpp"
#include <type_traits>
struct foo{
int& v() { return i; }
int i = 0;
};
int& x(int& i) { i = 42; return i;}
TEST_CASE("issue 14") {
tl::optional<foo> f = foo{};
auto v = f.map(&foo::v).map(x);
static_assert(std::is_same<decltype(v), tl::optional<int&>>::value, "Must return a reference");
REQUIRE(f->i == 42);
REQUIRE(*v == 42);
REQUIRE((&f->i) == (&*v));
}