|
Boost Users : |
From: Markus Werle (yg-boost-users_at_[hidden])
Date: 2003-06-02 08:03:34
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/
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