Add trait to check whether type is complete

This commit is contained in:
Martchus 2017-11-16 02:00:03 +01:00
parent a4e7cbd5c3
commit 2264ea5cf2
2 changed files with 10 additions and 0 deletions

View File

@ -48,6 +48,11 @@ struct IsCString
template <typename T> struct IsString : Bool<IsCString<T>::value || IsSpecializationOf<T, std::basic_string>::value> {
};
template <typename T, typename = void> struct IsComplete : Bool<false> {
};
template <typename T> struct IsComplete<T, decltype(void(sizeof(T)))> : Bool<true> {
};
/*!
* \def CPP_UTILITIES_PP_COMMA
* \brief The CPP_UTILITIES_PP_COMMA macro helps passing "," as a macro argument.

View File

@ -19,6 +19,8 @@ struct CountableStruct {
size_t size() const;
};
struct TestIncomplete;
static_assert(!Bool<false>::value, "Bool<false>");
static_assert(Bool<true>::value, "Bool<true>");
static_assert(!Not<Bool<true>>::value, "Not");
@ -56,3 +58,6 @@ static_assert(!IsString<stringstream>::value, "IsString: negative case");
static_assert(IsString<const char *>::value, "IsString: positive case");
static_assert(IsString<string>::value, "IsCString: positive case");
static_assert(IsString<u16string>::value, "IsCString: positive case");
static_assert(!IsComplete<TestIncomplete>::value, "IsComplete: negative case");
static_assert(IsComplete<CountableStruct>::value, "IsComplete: positive case");