Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-01-10 23:53:32

Stjepan Rajko wrote:

> FWIW, I have a use case in which a single function is used for all the
> cases, but it doesn't seem monolithic. Structurally it is very
> similar to the example given in the proposed library's documentation -
> the case function looks something like this:
> // get_port_c behaves similarly to fusion::at_c
> // port_t<T> is a run-time polymorphic class derived from port
> // the goal of this whole thing is to return a port * (port is the
> base class of a run-time polymorphic class hierarchy) from an object
> of some type T (T is required to model a certain concept - Port)

(snip use case similar to tutorial)

> "A" seems ideal for this use case. I have trouble seeing how to use
> "B" for it (easily) without making it so that the index is passed to
> the function object and allowing something like case<range>(...). But
> I might not be seeing all the possibilities. How can I implement this
> using "B"?

Ok, you are right. There is indeed no way to "bind" the
case (a compile time constant (e.g. mpl::int_)). It is
indeed crucial to have the case passed as the argument.
Once we have it, then (I'm inventing some more syntax):


Come to think of it, this is the only solution needed to map
an A-style all-in-one-function to B! No need for Fusion, no
need for extra infrastructure. All we need to do is pass
the case as an argument to f.

The key point (and one that I am trying to capture) is to define
the Concept of a Case. That is crucial. Once that's done, everything
flows naturally.


In addition to my suggested multiple case handling:

     case_<N, O, P, Q...>(f);

yes, perhaps it's also good to have a case range:

     case_range<From, To>(f);



Joel de Guzman

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