$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-10-20 18:47:43
On Sunday 19 October 2003 08:27 pm, Eric Friedman wrote:
> This is something I had been working on about two months ago but didn't
> post to the sandbox until recently.
>
> The basic idea is this:
>
> switch_( [variant] )
>
> |= case_< [pattern1] >(...)
> |= case_< [pattern2] >(...)
> |
> |= default_(...) // optional catch-all
>
> ;
>
> The switch_ will fail to compile if not every case is handled. In terms
> of handling, the case_ constructors take typical function objects,
> though the switch_ ignores any return values.
I would absolutely love to see this in the library. A while back (pre-variant)
I prototyped something similar for 'any' (with 'tuple' for product types)
that may be of interest:
http://article.gmane.org/gmane.comp.lib.boost.devel/311/match=typeswitch
The only things it did that I'd like to see in your version are:
1) Support for return types, as Brian already mentioned. I think this is
crucial.
2) I think I like putting the set of cases in brackets, but it's probably
Ocaml-envy kicking in:
switch_([variant])[
case_<[pattern1]> (...)
| case_<[pattern2]> (...)
| ...
| default_(...)
;
The syntactic bit is, of course, trivial and unnecessary. Pick whatever syntax
you like.
Doug