Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-06-07 06:36:34


Giovanni Piero Deretta wrote:

> I see two completely orthogonal fuctionalities here:
>
> 1- type erasure with multiple signatures of a single function object
> 2- aggregating different function objects in a single polymorphic
> function object *without* any type erasure at all.

That's what I've been saying for quite a while. MSF tries to do both,
but should only provide the first.

The second should be another tool, like egg::overload.
That kind of tool needs a lot of work alone.

I personally do not find egg::overload very satisfying. Lots of macros,
separate type definition and usage...
A solution like
http://groups.google.com/group/comp.std.c++/msg/34b98493a8531d58 seems
more elegant to me.
The problem being that it's not really possible, because the reflection
mechanism used by function objects doesn't allow rewriting their
signatures to forward to them.
Ideally, a system that works even with polymorphic functions would be
best, and if it doesn't require enumerating the signatures (they could
be deduced) even better.

By the way, is it possible to deduce the constraints of an argument type
and apply concept checking with SFINAE within a lambda expression DSEL?

Imagine if it was possible to write

auto f = overload(
    _1 + 42,
    unary_ellipsis(0)
);

_1 + 42 would be a function object similar to

auto concept IntAddable<typename T>
{
    /* don't really know how return type is to be specified */
operator+(T, int);
};

template<IntAddable T>
auto foo(T&& t) -> decltype(t + 42)
{
     return t + 42;
}

and f would be something like

template<IntAddable T>
auto f(T&& t) -> decltype(t + 42)
{
     return t + 42;
}

auto f(...) -> decltype(0)
{
    return 0;
}


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