Subject: Re: [boost] Discovering C++11 lambda argument and result types to construct boost::function
From: Frank Birbacher (bloodymir.crap_at_[hidden])
Date: 2012-02-11 13:45:14
-----BEGIN PGP SIGNED MESSAGE-----
Am 10.02.12 09:39, schrieb Andrzej Krzemienski:
> Sorry if this question is silly, but could you give me an example
> of where this deduction mechanism could be used?
The example I gave on comp.lang.c++.moderated is quite plain. The
make_function is used to construct a class template instatiation. I
think it compares to std::make_pair. I'll give another example below.
What I'm trying to work with is a lazy computation. My class template
Lazy<T> contains a variant over the type T and a function<T()> that
can produce a value of that type.
typedef T value_type;
typedef function<value_type()> lazy_function_type;
typedef variant<value_type, lazy_function_type> data_type;
if(auto* const p = boost::get<lazy_function_type>(&data))
data = (*p)();
The real task now is to create a make_lazy() function that constructs
a Lazy<T> from a lambda expression. Even when the target type is
somehow known there is still an advantage in convenience, esp. with
"auto var = make_lazy(...)." When calling template functions that take
Lazy<T> for some T the type deduction would not work with just a
I hope I could show to you that there is some usecase for make_function.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: keyserver x-hkp://pool.sks-keyservers.net
-----END PGP SIGNATURE-----