Boost logo

Boost Users :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2008-02-21 12:35:40


Gennadiy Rozental <rogeeff <at> gmail.com> writes:

> Here:
>
> http://www.rsdn.ru/forum/message/2720363.1.aspx
> http://www.rsdn.ru/forum/message/2759773.1.aspx
>

Thanks Gennadiy for the links, especially for the second one.

Two days ago I added recently reviewed boost::switch_ to my project
and was thinking of moving default case closer to all other cases.

So rather than

Cases f; Default dft;
switch_(n, f, dft);

I would like to switch_(n, f);

where Cases is

struct Cases {
  template<class N>
  void operator()(N) const { ... }

  void operator()(default_t) const { ... }
};

The trick posted on RSDN lets me check whether the last call operator
exists and take this into account.

One useful generalisation of this trick is something like

result_of_with_default<void (Cases)(default_t), no_default_case>

which would return no_default_case if you comment the last call operator
in Cases.

Many thanks,
Alex


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net