Boost logo

Boost :

Subject: Re: [boost] A more convenient Variant visitation syntax
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-04-14 19:32:22


On 14/04/12 18:39, Thomas Heller wrote:

> Phoenix didn't tackle that yet because it is a hard problem ... the
> main problem is the syntax how to express which lambda is responsible
> for what types.

One possible way: add information so that each node knows the type of
their arguments (with fallback to a template type if unknown).
Build operator() with those types instead of unconstrained templates.

You may also enhance the system by automatically deducing the type of an
argument even if it was not typed explicitly (e.g. because you did a
bind with a member function on it).

i.e.

apply_visitor( variant
              , make_overload( bind<int>(arg1)
                             , bind(arg1, &std::string::length)
                             )
              );

The function object resulting from bind<int>(arg1) would have an
operator() overload like

int operator()(int arg1);

while the function object resulting from bind(arg1,
&std::string::length) would have one like

size_t operator()(std::string& arg1);

the function object resulting from the make_overload call would have two
operator() overloads like

int operator()(int arg1);
size_t operator()(std::string& arg1);

So it will work just fine as a variant visitor.

> However, what's missing is something like a "catch all" aka a
> templated lambda...

You're getting that simply by not typing the arguments.


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