I'm new with templates and was wondering how I could do the following: I have a Fixed point structure that allows for fixed point calculations and is defined as follows:
template<int bits, int offset>
struct Fixed {
int64_t raw;
inline Fixed() {}
...
}
I'd like to expand this so that I can declare a self defined floating point representation and the compiler translates this to the correct fixed point definition. I tried this as follows:
template<int totBits, int expBits, int expOffset>
struct Fixed<exp2(expBits)+totBits-expBits-2,expOffset-totBits+expBits> {
inline Fixed() {}
inline explicit Fixed(double value) {
Quantization function of floating point here
}
};
However, this gives me the error: "Template argument involves template parameter(s)".
How can I remap the initial template such that I can do the following: fixed::Fixed<8,3,0> foo;
And the compiler sees this as: fixed::Fixed<11,-3> foo;
?
I know that when I assign a value to foo
I will have to manually quantise it as if it is stored as a floating point: e.g. foo = fixed::Fixed<8,3,0>(243)
which will give foo = 240 and foo = fixed::Fixed<8,3,0>(244)
will give foo = 248.
Aucun commentaire:
Enregistrer un commentaire