diff --git a/base/maybe.hpp b/base/maybe.hpp index a1fad48..34c2937 100644 --- a/base/maybe.hpp +++ b/base/maybe.hpp @@ -259,14 +259,14 @@ struct MaybeIfImpl { template -auto maybe_if(M& m, Functor function) +auto maybe_if(M&& m, Functor function) -> typename MaybeIfImpl::ResultType { return MaybeIfImpl::maybe_if(m, function); } template -auto maybe_if(M& m, Functor function) +auto maybe_if(M&& m, Functor function) -> typename MaybeIfImpl::ResultType { return MaybeIfImpl::maybe_if(m, function); diff --git a/test/Makefile b/test/Makefile index f6b54ee..6401342 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,13 +2,13 @@ CXXFLAGS = -O0 -g -I.. -std=c++11 -stdlib=libc++ -Wall -Werror -Wno-unused CXX = clang++ COMPILE = $(CXX) $(CXXFLAGS) -maybe_test: maybe_test.cpp ../maybe.hpp +maybe_test: maybe_test.cpp ../base/maybe.hpp $(COMPILE) -o maybe_test maybe_test.cpp -test: +test: maybe_test ./maybe_test clean: rm -f maybe_test -all: maybe_test \ No newline at end of file +all: maybe_test diff --git a/test/maybe_test.cpp b/test/maybe_test.cpp index 4146744..85f7d11 100644 --- a/test/maybe_test.cpp +++ b/test/maybe_test.cpp @@ -1,4 +1,4 @@ -#include "maybe.hpp" +#include "../base/maybe.hpp" #if defined(__has_feature) && __has_feature(cxx_lambdas) #define HAS_LAMBDAS 1 @@ -271,6 +271,15 @@ void test_maybe_if() { m = maybe_if(p, [](int it) { return it; }); ASSERT(!m); } + + // Test rvalue Maybe<> + { + int n = 123; + int observed = 0; + auto m = maybe_if(Maybe(123), [&](int it) { observed = it; }); + ASSERT(m); + ASSERT(observed == 123); + } } int main (int argc, char const *argv[]) @@ -375,5 +384,6 @@ int main (int argc, char const *argv[]) test_maybe_if(); + printf("All tests passed\n"); return 0; -} \ No newline at end of file +}