|
Boost Users : |
Subject: Re: [Boost-users] selecting a type (tag) based on a runtime enum value
From: John (john_at_[hidden])
Date: 2009-03-16 12:25:56
Not really. You've essentially got a map from ints to function calls. You could
implement it with an array of fps, a map container of some kind, a switch()
statement as you've done... and so on. There are so many way to implement it,
and they're all more or less the same. I'd choose the most readable,
maintainable, debuggable, and which makes the most use of the compiler to
enforce constraints. Using that criteria, the switch is actually a good
candidate. (Helpful tip: Don't include a `default` case, and enable GCC's
-Wswitch or your compiler's equivalent warning).
Hicham Mouline wrote:
> Hello,
>
> I have a templated function Engine, that takes 3 template arguments,
> these are tags T1, T2, T3, T4.
>
> I have an
> typedef enum { e1, e2, e3, e4 } E
> to element ei corresponds the type Ti
>
> ...
> const E e //
> switch (e)
> {
> case e1:
> Engine< Metafct1<T1>::type, Metafct2<T1>::type, Metafct3<T1>::type >::Process( .... ); break;
> case e2:
> Engine< Metafct1<T2>::type, Metafct2<T2>::type, Metafct3<T2>::type >::Process( .... ); break;
> ...
> }
>
>
> Is there a shorter way of writing this... For now I only have 4 in the enum, but I may have more later?
>
> regards,
> _______________________________________________
> 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