Boost logo

Boost :

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

Hash: SHA1


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.

template<typename T>
struct Lazy<T>
  typedef T value_type;
  typedef function<value_type()> lazy_function_type;
  typedef variant<value_type, lazy_function_type> data_type;
  data_type data;


  value_type& get()
    if(auto* const p = boost::get<lazy_function_type>(&data))
      data = (*p)();
    return boost::get<value_type>(data);

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
lambda expression.

I hope I could show to you that there is some usecase for make_function.

Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools -
Comment: keyserver x-hkp://


Boost list run by bdawes at, gregod at, cpdaniel at, john at