Boost logo

Boost :

Subject: Re: [boost] An open typeswitch using lambdas
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-11-30 08:11:42

On 30/11/2013 09:37, Matt Calabrese wrote:
> On Fri, Nov 29, 2013 at 11:47 PM, Sumant Tambe <sutambe_at_[hidden]> wrote:
>> Well, gcc 4.9 has a name lookup bug (

The bug is probably just worked around by using "using operator()".
When I was experimenting with that kind of thing, it worked just fine.

>> and Visual Studio 2013
>> Nov CTP chokes on lambda multiple inheritance.

You could wrap lambdas into proper function objects to work around this.

> If you want to support type-erased
> objects, it's not quite that simple, though I personally am not very
> interested in those capabilities. At the very least, it should be possible
> to make the simple, overload-based one without the overhead of a more
> dynamic approach.

The "open" in "open typeswitch" means that it doesn't require a closed
set of types.

The open aspect is difficult to do properly. The issues to me with the
kind of implementation used here is that it has too big a requirement on
the function objects to handle the different cases, doesn't deal well
with conversions, cannot use generic code etc. If we had stuff like
virtual templates it would be possible to treat open and closed type
switch the same way, but emulating virtual templates by hand is a bit

> Anyway, regardless of the implementation, I do think that this is a
> worthwhile tool. Make it inherit from boost::static_visitor and I'll start
> using as soon as I can.

AFAIK variant doesn't require that your visitors inherit from
static_visitor, just that they define the result_type typedef.

Boost list run by bdawes at, gregod at, cpdaniel at, john at