jeudi 28 mai 2015

Testing template based class with const template parameter which has to be varied

I am developing a template based library to support fixed point integers and I came up with this class and now I have to test it for various values of INT_BITS and FRAC_BITS. but since they are const (and they have to be so for a reason), I am unable to initialize objects with variable INT_BITS in a loop and hence it is making testing this library very difficult.

template<int INT_BITS, int FRAC_BITS>
struct fp_int
{
     public:
            static const int BIT_LENGTH = INT_BITS + FRAC_BITS;
            static const int FRAC_BITS_LENGTH = FRAC_BITS;
     private:
            // Value of the Fixed Point Integer 
            ValueType stored_val;
};

I tried a lot of tricks mentioned here , here and here. I tried using a std::vector of const int and const_cast but nothing seems to work.

I was wondering that that how do you test such libraries where the template parameter is a const for a large test values ?

Aucun commentaire:

Enregistrer un commentaire