Browse Source

Fix Traits::IsSpecializationOf for references

This check is also supposed to work for references so use the same approach
as for ignoring cv qualifiers.
charconv
Martchus 1 year ago
parent
commit
9d59ab5c29
  1. 5
      misc/traits.h
  2. 3
      tests/traitstests.cpp

5
misc/traits.h

@ -65,9 +65,10 @@ template <template <typename...> class Template, typename... Args> struct IsSpec
};
} // namespace Detail
/// \endcond
/// \brief Evaluates to Bool<true> if the specified type is based on the specified \tparam Template; otherwise evaluates to Bool<false>.
/// \brief Evaluates to Bool<true> if the specified type is based on the specified template; otherwise evaluates to Bool<false>.
template <typename Type, template <typename...> class... TemplateTypes>
struct IsSpecializationOf : Detail::IsSpecializationOfHelper<typename std::remove_cv<Type>::type, TemplateTypes...> {
struct IsSpecializationOf
: Detail::IsSpecializationOfHelper<typename std::remove_cv<typename std::remove_reference<Type>::type>::type, TemplateTypes...> {
};
/// \brief Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise evaluates to Bool<false>.
template <typename Type, template <typename...> class... TemplateTypes> struct IsSpecializingAnyOf : Bool<false> {

3
tests/traitstests.cpp

@ -43,6 +43,9 @@ static_assert(None<Bool<false>, Bool<false>>::value, "None: positive case");
static_assert(!IsSpecializationOf<string, basic_stringbuf>::value, "IsSpecializationOf: negative case");
static_assert(IsSpecializationOf<string, basic_string>::value, "IsSpecializationOf: positive case");
static_assert(IsSpecializationOf<string &, basic_string>::value, "IsSpecializationOf: positive case");
static_assert(IsSpecializationOf<const string &, basic_string>::value, "IsSpecializationOf: positive case");
static_assert(IsSpecializationOf<volatile string, basic_string>::value, "IsSpecializationOf: positive case");
static_assert(!IsSpecializingAnyOf<string, basic_stringbuf, vector>::value, "IsSpecializingAnyOf: negative case");
static_assert(!IsSpecializingAnyOf<string, basic_stringbuf, list, vector>::value, "IsSpecializingAnyOf: negative case");
static_assert(IsSpecializingAnyOf<string, basic_stringbuf, basic_string, vector>::value, "IsSpecializingAnyOf: positive case");

Loading…
Cancel
Save