Is there an easy way to tell if a class/struct has no data members?
Hallo, is there some easy way in C++ to tell (in compile-time) if a class/struct has no data members? E.g. struct T{}; My first thought was to compare sizeof(T)==0 , but this always seems to be at least 1. The obvious answer would be to just look at the code, but I would like to switch on this. Konrad Rudolph Since C++11, you can use standard std::is_empty trait: https://en.cppreference.com/w/cpp/types/is_empty If you are on paleo-compiler diet, there is a trick: you can derive from this class in another empty and check whether sizeof(OtherClass) == 1 . Boost does this in its is_empty type