Boost logo

Boost :

Subject: Re: [boost] Call for interest - BOOST_AUTO_FUNCTION
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2010-10-10 13:50:36


On Sun, Oct 10, 2010 at 8:02 AM, Yechezkel Mett <ymett.on.boost_at_[hidden]>wrote:
>
> Why not simply
>
> auto name = [&](param_list){ return expression; }
>

That doesn't work when the function itself should be a template, which is
the motivating case. Please see the code example I linked -- in my macro I
don't have "template< typename Param >" or something similar because that
part of the code is better off to not directly be a part of the macro itself
for various reasons. Refer to the multi_cast code I linked for an example of
that. The point of the macro is to allow you to define a function template
that can be called with arguments of an appropriate type and have the return
type be deduced automatically, it should be just as capable as any other
function template that you would write as in you should be able to call it
with any arguments that model the corresponding concepts as opposed to
specific types, it should be able to be overloaded, you should be able to
explicitly specify template arguments, etc. These capabilities are not
possible with 0x lambdas because they themselves cannot directly be
templates (sadly).

0x lambdas do not solve all of our problems here, and, sorry for a slightly
off-topic rant in my own thread, don't even solve the problem of creating
unnamed function objects in general. While they provide a way to make using
standard library algorithms easier to use, they fall flat when writing
things such as "callable objects" for Boost.Fusion algorithms or visitors
for Boost.Variant (in all but the most trivial of special cases for
Boost.Fusion). For those situations you still need to write more traditional
function objects, often with an operator () template and/or overloads.
Trying to simulate named functions with automatically deduced return types
via lambdas by using auto, while will work for trivial function objects,
simply cannot work for function templates and is, IMHO, much more of a hack
than using a macro that expands to precisely what is desired.

Yes, resorting to macros is unfortunate, but I really don't think there is
any other option here.

-- 
-Matt Calabrese

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