Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-01-11 22:42:10


Joel de Guzman wrote:

> I'll try to come up with a complete interface proposal that
> will encompass all use cases. It will be lightweight (no need
> for extra infrastructure) and efficient. I believe it can
> be done.

Ok, here's what I have for draft of the Case concept.
I believe this is most crucial in the design of the
switch_ as I proposed in a recent post. Comments,
feedback, suggestions welcome.

Case Concept:
     Specialization of unary Polymorphic Function Object that,
     in addition to the requirements defined in Polymorphic
     Function Object, encodes a list of labels in its type
     necessary for switch dispatch.

Notation:

     c, c0, c1, ... cN Case objects
     C A Case type
     I An MPL Integral Constant type
     i An MPL Integral Constant object
     N, First, Last Integral constants
     N0, N1, ...NN A list of integral constants
     f A unary function
     case_c, case_range_c,
     case_, default Case factories

Valid Expressions:

     Expression Semantics
     ----------
--------------------------------------------------------
     C::labels An MPL Sequence of Integral Constants
     c(i) Function application
     case_<I>(f) Returns a Case object with supplied
                             MPL Sequence of Integral Constants.
                             forwarding to the encapsulated function object f.
     case_c<N>(f) Returns a Case object with a single label N
                             forwarding to the encapsulated function object f.
                             Equivalent to: case_<mpl::vector_c<int, N> >(f)
     case_c<
         N0, N1, ...NN>(f) Returns a Case object with a list of labels
                             forwarding to the encapsulated function object f.
                             Equivalent to: case_<mpl::vector_c<
                               int, N0, N1, ...NN> >(f)
     case_range_c<
         First, Last>(f) Returns a Case object with a range of labels
                             forwarding to the encapsulated function object f.
                             Equivalent to: case_<mpl::range_c<
                               int, First, Last> >(f)
     default_(f) Returns a Case object with an empty labels list.
                             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 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, but a
     variation is to have case_c and case_range_c expect the
     actual type (like mpl::vector_c and mpl::range_c.). E.g.:
     case_c<int, N>.

   * case_<I>(f) is equivalent to the original Steven interface.

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.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