Skip to content

Commit

Permalink
Maybe<T>: Fixed some constedness.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonask committed May 24, 2012
1 parent a04a453 commit 1dec8cd
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions maybe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Maybe {
}
template <typename Functor>
auto map(Functor functor) const
-> typename MaybeIfImpl<Maybe<T>, decltype(functor(infer_value_type()))>::ResultType {
return MaybeIfImpl<Maybe<T>, decltype(functor(infer_value_type()))>::maybe_if(*this, functor);
-> typename MaybeIfImpl<const Maybe<T>, decltype(functor(infer_value_type()))>::ResultType {
return MaybeIfImpl<const Maybe<T>, decltype(functor(infer_value_type()))>::maybe_if(*this, functor);
}
private:
template <typename M, typename ReturnType> friend struct MaybeIfImpl;
Expand Down Expand Up @@ -244,12 +244,6 @@ struct MaybeIfImpl<M, void> {
if (m) { function(*m); return true; }
return false;
}

template <typename Functor>
static BooleanHolder maybe_if(const M& m, Functor function) {
if (m) { function(*m); return true; }
return false;
}
};

template <typename M, typename ReturnType>
Expand All @@ -261,12 +255,6 @@ struct MaybeIfImpl {
if (m) return function(*m);
return ResultType();
}

template <typename Functor>
static ResultType maybe_if(const M& m, Functor function) {
if (m) return function(*m);
return ResultType();
}
};


Expand All @@ -277,25 +265,17 @@ auto maybe_if(M& m, Functor function)
return MaybeIfImpl<M, decltype(function(m.infer_value_type()))>::maybe_if(m, function);
}

template <typename M, typename Functor>
auto maybe_if(const M& m, Functor function)
-> typename MaybeIfImpl<M, decltype(function(m.infer_value_type()))>::ResultType
{
return MaybeIfImpl<M, decltype(function(m.infer_value_type()))>::maybe_if(m, function);
}

template <typename M, typename Functor>
auto maybe_if(M& m, Functor function)
-> typename MaybeIfImpl<M, decltype(function(*m))>::ResultType
{
return MaybeIfImpl<M, decltype(function(*m))>::maybe_if(m, function);
}

template <typename M, typename Functor>
auto maybe_if(const M& m, Functor function)
-> typename MaybeIfImpl<M, decltype(function(*m))>::ResultType
{
return MaybeIfImpl<M, decltype(function(*m))>::maybe_if(m, function);
template <typename OutputStream, typename T>
OutputStream& operator<<(OutputStream& os, const Maybe<T>& m) {
maybe_if(m, [&](const T& it) { os << it; }).otherwise([&]() { os << "(none)"; });
return os;
}

#endif /* end of include guard: MAYBE_HPP_8R2MUT0P */

0 comments on commit 1dec8cd

Please sign in to comment.