Topic: Toward a Monads proposal - providing generic make_
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 26 Jan 2014 09:11:33 +0100
Raw View
Hi,
We will have
template <class T, class... Args> unique_ptr<T> make_unique(Args&&...
args);
template<class T, class... Args> shared_ptr<T> make_shared(Args&&...
args);
and possibly
template <class T> constexpr optional<decay_t<T> make_optional(T&&);
template <class T> constexpr future<decay_t<T>> make_ready_future(T&&);
template <class T> constexpr expected<decay_t<T>> make_expected(T&&);
It would be great to have a generic make function taking the monad as
template parameter in addition
template <class M, class X>
constexpr M make(X&&);
template <template<class...> M, class X>
constexpr M<X> make(X&&);
that can be used as
int v=0;
make<shared_ptr>(v);
make<unique_ptr>(v);
make<optional>(v);
make<future>(v);
make<shared_future>(v);
make<expected>(v);
or as
make<shared_ptr<uint&>>(v);
make<unique_ptr<uint&>>(v);
make<optional<uint>>(v);
make<future<int&>>(v);
make<shared_future<int&>>(v);
make<expected<int>(v);
Note that currently it is not possible to do the following
future<int&> f = make_ready_future(v);
as the future value_type is decayed
and that the function make_ready_shared_future() has not been proposed
as the user can
auto f = make_ready_future(v).share();
IMO, these corner cases should be avoided and having a generic interface
would help to make generic algorithms.
The definition off these make function could be based on the Monad
library defined in "Monads in C++" (see
http://yapb-soc.blogspot.fr/2012/10/monads-in-c.html)
The linked implementation doesn't contains the variadic emplace version
of mreturn which shoul dbe also added to take care of the existing make_
functions.
template <class M, class ...Args>
constexpr M make(Args&&...);
Of course Monad provide also the generic function mbind (similar to the
future::then() proposal).
Making these functions generic would help to build on top of algorithms
working on monads.
Would you like to see something like this on the standard?
Best,
Vicente
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.