Von: Andrzej Krzemienski [via Boost] [mailto:ml-node+s2283326n4677451h87@n4.nabble.com]
Gesendet: Montag, 22. Juni 2015 20:54
An: Löw, Tobias (STEAG Energy Services GmbH)
Betreff: Re: [Optional] Monadic bind
2015-06-22 16:59 GMT+02:00 Tobias Loew <[hidden email]>:
I deliberately used this std::bind syntax since it accepts any callable
(including things like pointer-to-member [functions]).
I tried lambdas with my code and they just work. E.g.
auto opt_i3 = map(opt_a, [](const A& a){ return a.i;});
assert(*opt_i3 == 42);
Interesting. Is it implementable in C++03?
I managed to change your map2 to compile in C++03 (on VS 2008)
template
boost::optional<
typename boost::remove_cv<
typename boost::remove_reference<
typename boost::result_of::type
>::type
>::type
>
map2(const boost::optional<T>& o, F f)
{
if (o) return f(*o);
else return boost::none;
}
I didn’t find an easy way to make my map compile in C++03. Technically, it should be possible by using the same tricks that boost::bind itself uses, but I think that would be by far too much for such a feature.
A good solution could be: using a map2-like version (only accepting functions/functors) for C++03 compilers and a the more general version (accepting arbitrary callables) for C++11 compilers.
--
View this message in context: http://boost.2283326.n4.nabble.com/Optional-Monadic-bind-tp4677431p4677464.h...
Sent from the Boost - Dev mailing list archive at Nabble.com.