Boost logo

Boost Users :

From: Bruce Trask (Bruce.Trask_at_[hidden])
Date: 2005-03-31 11:45:05


Hi,

I coded up the mpl::map versus the SWITCH approach and I am thinking
that the SWITCH approach is better in this case as it shows the various
mnemonic choices at the point of the SWITCH. Thoughts?

Also if the SWITCH is the better way to go, it leads me to my original
question as to whether there is a mpl::switch?

enum tagit
  {
    one,
    two,
    three
  };

struct First
{
  static void func()
  {
    cout << "First" << endl;
  }
};

struct Second
{
  static void func()
  {
    cout << "Second" << endl;
  }
};

struct Third
{
  static void func()
  {
    cout << "Third" << endl;
  }
};

typedef mpl::map<
                 mpl::pair<mpl::integral_c<tagit, one>, First>,
                 mpl::pair<mpl::integral_c<tagit, two>, Second>,
                 mpl::pair<mpl::integral_c<tagit, three>, Third>
> funcchooser;

template<tagit ti>
void funcCaller()
{

  SWITCH<ti, CASE<one, First, CASE<two, Second, CASE<three, Third> > >
>::RET::func();

  mpl::at<funcchooser, mpl::integral_c<tagit, ti> >::type::func();
  
}
int main()
{
  funcCaller<one>();
  funcCaller<two>();
  funcCaller<three>();
  
  return 0;
}

Thanks,

Bruce
On Thu, 2005-03-31 at 10:37 -0500, Bruce Trask wrote:
> Hi,
>
> Now that I am thinking about it, I could use mpl::map for this right?
>
> Regards,
> Bruce
>
> On Thu, 2005-03-31 at 09:38 -0500, Bruce Trask wrote:
> > Hi,
> >
> > Is there a boost::switch so I can do type selection similar to mpl::if_
> > but with more than two types? I looked but could not find it.
> >
> > Or should I just use the implementation of SWITCH in the Generative
> > Programming book?
> >
> > Regards,
> > Bruce
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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