Is there a way to static_assert that a type T is Not complete at that point in a header? The idea is to have a compile error if someone adds #includes down the road in places they should not be.
related: How to write `is_complete` template?
Using that link's answer,
namespace
{
template<class T, int discriminator>
struct is_complete {
static T & getT();
static char (& pass(T))[2];
static char pass(...);
static const bool value = sizeof(pass(getT()))==2;
};
}
#define IS_COMPLETE(X) is_complete<X,__COUNTER__>::value
class GType;
static_assert(!IS_COMPLETE(GType),"no cheating!");
unfortunately this gives "invalid use of incomlete type" error, d'oh. Is there a way to assert on the negation?
()`. `std::declval` gives you an rvalue reference so you don't need to use constructors that may or may not exist. However, yes, it was all completely unnecessary in the first place because I'm dumb and `sizeof` works on types.– chris Sep 11 '14 at 20:39