
Hi! The following piece of code works (finally, sigh), but I would like to hear some comments on whether and how one can do better. #include "boost/mpl/apply_if.hpp" #include "boost/mpl/identity.hpp" #include "boost/mpl/lower_bound.hpp" #include "boost/mpl/deref.hpp" #include "boost/mpl/find.hpp" #include "boost/mpl/vector.hpp" #include "boost/mpl/pair.hpp" #include "boost/mpl/bool.hpp" #include "boost/mpl/select1st.hpp" #include "boost/mpl/select2nd.hpp" #include "boost/mpl/lambda.hpp" #include "boost/type_traits/is_same.hpp" #include <typeinfo> #include <iostream> namespace mpl = boost::mpl; template <int m, int n> class ComplicatedDecision { private: template <int i> struct C { // typedef probably_very_expensive_template type; }; // order matters typedef mpl::vector < mpl::pair<mpl::bool_< (m == n) >, C<0> >, mpl::pair<mpl::bool_< (m == -n) >, C<1> >, mpl::pair<mpl::bool_< (m == 1) >, C<2> >, mpl::pair<mpl::bool_< (m < 0) >, C<3> >, mpl::pair<mpl::bool_< true >, C<4> >
decision_sequence;
typedef typename mpl::find_if< decision_sequence, boost::is_same<mpl::select1st<mpl::_1>, mpl::bool_<true> > > iter_; typedef typename iter_::type::type pair_; public: typedef typename mpl::select2nd<pair_>::type type; }; int main() { std::cerr << typeid(ComplicatedDecision<1,1>::type).name() << std::endl; std::cerr << typeid(ComplicatedDecision<-1,1>::type).name() << std::endl; std::cerr << typeid(ComplicatedDecision<1,2>::type).name() << std::endl; std::cerr << typeid(ComplicatedDecision<-1,2>::type).name() << std::endl; std::cerr << typeid(ComplicatedDecision<2,3>::type).name() << std::endl; } best regards, Markus -- Compile time analytic differentiation? Yes, at http://daixtrose.sourceforge.net/

Markus Werle <yg-boost-users@m.gmane.org> writes:
Hi!
The following piece of code works (finally, sigh), but I would like to hear some comments on whether and how one can do better.
You could remove the illegal "typename" in this line: typedef typename mpl::find_if< It's hard to comment further when I have no idea what it's supposed to be doing. Comments or a little exposition would be a big help. -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Abrahams wrote:
You could remove the illegal "typename" in this line:
typedef typename mpl::find_if<
incredible how sloppy compilers are ...
It's hard to comment further when I have no idea what it's supposed to be doing.
It is supposed to do what it does :-) My question is, whether the code above could be optimized regarding compile time or compactness or whether I missed another feature of mpl.
Comments or a little exposition would be a big help.
The real life version is at http://tinyurl.com/df99 search for: template <class WRT, int mm, int nn, class ARG> struct DiffImpl<WRT, Daixt::UnOp<ARG, Daixt::DefaultOps::RationalPower<mm, nn> > > best regards, Markus
participants (2)
-
David Abrahams
-
Markus Werle