Boost logo

Boost :

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:

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

  2) I think I like putting the set of cases in brackets, but it's probably
Ocaml-envy kicking in:

  case_<[pattern1]> (...)
  | case_<[pattern2]> (...)
  | ...
  | default_(...)

The syntactic bit is, of course, trivial and unnecessary. Pick whatever syntax
you like.


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