Re: [Boost-users] [boost] [switch_] Case Concept [ was Re: formal review of Switch library...]

AMDG Joel de Guzman wrote:
Valid Expressions:
Expression Semantics ---------- -------------------------------------------------------- C::labels An MPL Sequence of Integral Constants
I think that a case should only have a single label. Allowing multiple labels makes the implementation harder without adding any significant utility. See below.
case_<I>(f) Returns a Case object with supplied <snip more generators>
These can return fusion sequences of cases instead of plain cases. This has the additional benefit that switch_ can be specified as taking a fusion sequence of cases, without having to handle a single case specially.
default_(f) Returns a Case object with an empty labels list. forwarding to the encapsulated function object f.
From the standpoint of the implementor of switch_, how do I figure out which Case is the default?
* case_c and case_range_c are simple shortcuts. The type of integral constant is int. The actual type can be casted to the actual switch parameter. I think this is safe
Since the value is known at compile time the cast can be checked at compile time to detect overflow. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Joel de Guzman wrote:
Valid Expressions:
Expression Semantics ---------- -------------------------------------------------------- C::labels An MPL Sequence of Integral Constants
I think that a case should only have a single label. Allowing multiple labels makes the implementation harder without adding any significant utility. See below.
Hmmm... Good point. So, we basically break a Case with one or more labels to atomic parts? Nice.
case_<I>(f) Returns a Case object with supplied <snip more generators>
These can return fusion sequences of cases instead of plain cases. This has the additional benefit that switch_ can be specified as taking a fusion sequence of cases, without having to handle a single case specially.
Right! Makes sense. But wouldn't that use more compile time resources? Well, you know better :-)
default_(f) Returns a Case object with an empty labels list. forwarding to the encapsulated function object f.
From the standpoint of the implementor of switch_, how do I figure out which Case is the default?
I thought it would be just a check:
mpl::empty
* case_c and case_range_c are simple shortcuts. The type of integral constant is int. The actual type can be casted to the actual switch parameter. I think this is safe
Since the value is known at compile time the cast can be checked at compile time to detect overflow.
Oh, so, you are also in favor of the former? So we all are. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

AMDG Joel de Guzman wrote:
Steven Watanabe wrote:
case_<I>(f) Returns a Case object with supplied <snip more generators>
These can return fusion sequences of cases instead of plain cases. This has the additional benefit that switch_ can be specified as taking a fusion sequence of cases, without having to handle a single case specially.
Right! Makes sense. But wouldn't that use more compile time resources? Well, you know better :-)
I don't think so. I'd have to flatten the sequence anyway. This way you don't pay for it if you're not using it.
From the standpoint of the implementor of switch_, how do I figure out which Case is the default?
I thought it would be just a check:
mpl::empty
But if you want single labels for each Case, then, perhaps:
is_same
or somesuch. Am I missing something
Ok. I didn't like mpl::empty because of the following possibility: switch_<r>(n)(case_range_c<0, N>(f), default(f)); If N is zero there's a problem. In Christ, Steven Watanabe

Steven Watanabe wrote:
From the standpoint of the implementor of switch_, how do I figure out which Case is the default?
I thought it would be just a check:
mpl::empty
But if you want single labels for each Case, then, perhaps:
is_same
or somesuch. Am I missing something
Ok. I didn't like mpl::empty because of the following possibility:
switch_<r>(n)(case_range_c<0, N>(f), default(f));
If N is zero there's a problem.
Is case_range_c<0, 0> a valid case? If so, it can simply amount to a no-op (ignored). It won't match anything anyway. But, my instincts tell me that case_range_c should expect a valid range. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (2)
-
Joel de Guzman
-
Steven Watanabe