Browse Source

Add trait to check whether type is complete

experiment/improve_get_date_part
Martchus 4 years ago
parent
commit
2264ea5cf2
  1. 5
      misc/traits.h
  2. 5
      tests/traitstests.cpp

5
misc/traits.h

@ -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.

5
tests/traitstests.cpp

@ -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");

Loading…
Cancel
Save