
Boost : 
From: Joel de Guzman (joel_at_[hidden])
Date: 20080113 02:40:52
Joel de Guzman wrote:
> I'll see if I can post an update from yours and Steven's
> comments.
Ok, here's the update:
Case Concept:
Specialization of unary Polymorphic Function Object that,
in addition to the requirements defined in Polymorphic
Function Object, encodes a label in its type necessary
for switch dispatch.
Notation:
c, c0, c1, ... cN Case objects
C A Case type
I An MPL Integral Constant type
SI An MPL Sequence of Integral Constant types
i An MPL Integral Constant object
N, First, Last Integral constants
N0, N1, ...NN A list of integral constants
f A unary function
cases_c, case_c,
case_range_c, case_,
cases, default Case factories
Valid Expressions:
Expression Semantics
 
C::label An MPL Integral Constant or none
(none type is used to signal the default case).
c(i) Function application. Equivalent to c(I()).
case_<I>(f) Returns a single element fusion sequence containing
a Case object with supplied MPL Integral Constant,
forwarding to the encapsulated function object f.
cases<SI>(f) Returns a fusion sequence of Case objects with
labels corresponding to each element of the
supplied MPL Sequence of Integral Constants,
forwarding to the encapsulated function object f.
case_c<N>(f) Returns a single element fusion sequence containing
a Case object with supplied label N, forwarding to
the encapsulated function object f. Equivalent to:
case_<mpl::int_<N> >(f).
cases_c<
N0, N1, ...NN>(f) Returns a fusion sequence of Case objects with
labels N0, N1, ...NN, forwarding to the encapsulated
function object f. Equivalent to:
cases<mpl::vector_c<int, N0, N1, ...NN> >(f)
case_range_c<
First, Last>(f) Returns a fusion sequence of Case objects with
labels mpl::int_<First> ... mpl::int_<Last>,
forwarding to the encapsulated function object
f. Equivalent to:
cases<mpl::range_c<int, First, Last> >(f)
default_(f) Returns a single element fusion sequence containing
a Case object with a none label, forwarding to the
encapsulated function object f.
c0, c1, ... cN Returns a fusion sequence of Case objects.
Notes:
* While c0, c1, ... cN returns a fusion sequence, it does not
have to use Fusion. It can be a very simple cons list of
references to the actual arguments similar to the zero overhead
Proto expression tree. It must be compatible with Fusion though,
but that can be abstracted away.
* case_c, cases_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. Since the value is known at compile
time the cast can be checked at compile time to detect overflow.
* cases<SI>(f) is equivalent to the original Steven interface.
Regards,
 Joel de Guzman http://www.boostconsulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk