samedi 24 septembre 2016

C++ template specialization not working when comparing sizeof(type) == constant

int ReadInt() { ... }
longlong ReadLong() { ... }

template<class MySizeType>
class MyType
{
  public:
    MySizeType Field;
    MyType()
    {
       Field = sizeof(MyType) == 4 ? ReadInt() : ReadLong();
    }
}

I get a compiler warning because it looks like the the condition sizeof(MyType) == 4 is not being evaluated at compile time.

If it were we would have specialization and this wouldn't be a problem.

Anyway I could achieve this?

Aucun commentaire:

Enregistrer un commentaire