|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-08-22 15:20:08
AMDG
Mathias Gaunard <mathias.gaunard <at> etu.u-bordeaux1.fr> writes:
>
> I don't know how boost.lambda actually does it, but on my x86 box,
> sizeof(_1 + a + b) yields 12, which means there is an overhead of one
> word for some reason.
_1 takes up space because lambda doesn't try to use EBO.
> We are rather sure to have it well optimized if we do this though:
>
> <snip>
>
> It would be nice if we had a lambda engine that could automatically do
> such magic. This would probably require the use of macros though.
What you want is:
template<class F>
struct function_reference {
function_reference(F& func) : f(boost::addressof(func)) {}
template<class T...>
decltype(make<F&>()(make<T>()...)) operator()(T&&... t) {
return((*f)(t...));
}
F* f;
};
template<class F>
function_reference<F> func_ref(F& f) {
return(function_reference<F>(f));
}
BOOST_AUTO(lambda, _1 + a + b);
BOOST_AUTO(f, func_ref(lambda));
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk