C++ variable to const expression
- by user1344784
template <typename Real>
class A{ };
template <typename Real>
class B{ };
//... a few dozen more similar template classes
class Computer{
public slots:
void setFrom(int from){ from_ = from; }
void setTo(int to){ to_ = to; }
private:
template <int F, int T> void compute(){
using boost::fusion::vector;
using boost::fusion::at_c;
vector<A<float>, B<float>, ...> v;
at_c<from_>(v).operator()(at_c<to_>(v)); //error; needs to be const-expression.
};
This question isn't about Qt, but there is a line of Qt code in my example.
The setFrom() and setTo() are functions that are called based on user selection via the GUI widget. The root of my problem is that 'from' and 'to' are variables. In my compute member function I need to pick a type (A, B, etc.) based on the values of 'from' and 'to'. The only way I know how to do what I need to do is to use switch statements, but that's extremely tedious in my case and I would like to avoid. Is there anyway to convert the error line to a constant-expression?