Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-06-28 22:37:14


Atry wrote:
> It can not work now. But I will make expressions like
> BOOST_STATIC_LAMBDA_FUNCTOR(_1 + _2) always worked for both native or
> emulated typeof this week.

Atry, I started replying immediately but I realised that I should take a
closer look at your code. Unfortunately, I didn't have time.

So, I started with:

Is it possible to get rid of the BOOST_STATIC_LAMBDA_FUNCTOR macro
completely? I'm thinking of this interface:

// Return an object of unspecified type F such that
// F::invoke(arg1, ...) [static] - equivalent to invocation of expr(arg1, ...)
// F::get_static_function<Sig>() [static] - return an address of
// F::invoke<Arg1, ...> where Sig is a function type R(Arg1, ...).
template<class Expr>
typename resultof_make_static_functor<Expr>::type make_static_functor(Expr);

template<class Sig, class Expr>
Sig* make_static_function(Expr)
{
    return make_static_functor(expr)::get_static_function<Sig>();
}

Some examples:

make_static_functor(_1 + _2)::invoke(1, 2);

typedef BOOST_TYPEOF( make_static_functor(_1 + _2) ) my_static_lambda;

// ( assuming you support stateful lambdas )
int (*inc)(int const&) = make_static_function<int(int const&)>(_1 + 1);

> Unfortunately, BOOST_STATIC_LAMBDA_FUNCTOR(_1 +
> _2 * _1)::static_invoke(custom_value1, custom_value2) will never work if
> result of custom_value2*custom_value1 or
> custom_value1+custom_value2*custom_value1 is a unregistered type for the
> platform does not have native typeof. The client not have native typeof have
> to register all type may be evaluated is registered.

I stopped here because I couldn't make a good comment without
understanding BOOST_STATIC_LAMBDA_FUNCTOR internals.

Now, rather than commenting your statements I'd like to add a more
general comment.
In your previous post you wrote "I use typeof to determine the
result of almost all expressions, and Boost.Lambda does not".
Unfortunately, it's not always possible to add cool things to a
library because it should support broken compilers, it should not
break existing code (a need to register every type in emulation
mode is a breaking change) and so on.
Your change should be consistent with a rest of library.
Typeof stuff can wait. I'm sure there will be an interest in this
change for the whole library, not only for your small addition.

-- 
Alexander Nasonov - http://nasonov.blogspot.com
A friend is the hope of the heart. -- Ralph Waldo Emerson --
/---------------------------- Fortune script ----------------------------\
curl 'http://www.quotedb.com/quote/quote.php?action=random_quote&=&=&' | \
    sed -e "s/^[^']*'//;s/.);$/ --/;s/<[^>]*>//g;2s/^.\{17\}//"        | fmt

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk