Home > other >  Is there a SFINAE-template to check if a class has no functions of any kind?
Is there a SFINAE-template to check if a class has no functions of any kind?

Time:01-04

I want to check if a given class has only the following:

  • Non-static data members
  • Constructor(s) (default or user-defined)
  • Destructor (default or user-defined)

This type would be (at least visually declaration-wise) identical to a POD-type apart from the user-defined constructor and destructor. I've tried to find a term for this kind of type but I don't think it exists.

Is there a way to check this, using some SFINAE-hackery?

CodePudding user response:

No, there's no such method. Consider the following:

struct A { };
struct B { void UniqueFunctionName9814(); };

No SFINAE method can distinguish these, because you can't enumerate member function names, nor can you predict random function names. Hence B::UniqueFunctionName9814 can't be detected, and apart from B::UniqueFunctionName9814 the two classes are identical.

  • Related