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
class ComplicatedDecision
{
private:
template <int i> struct C {
// typedef probably_very_expensive_template type;
};
// order matters
typedef mpl::vector
<
mpl::pair, C<0> >,
mpl::pair, C<1> >,
mpl::pair, C<2> >,
mpl::pair, C<3> >,
mpl::pair, C<4> >
decision_sequence;
typedef typename mpl::find_if<
decision_sequence,
boost::is_samempl::_1,
mpl::bool_<true> > >
iter_;
typedef typename iter_::type::type pair_;
public:
typedef typename mpl::select2nd::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/