Add trait to test for strings

testing/bash_completion_debugging
Martchus 5 years ago
parent 7faa51c10e
commit 3b74b817ec
  1. 7
      misc/traits.h
  2. 12
      tests/traitstests.cpp

@ -41,6 +41,13 @@ template <typename T, template <typename...> class Template> struct IsSpecializa
template <template <typename...> class Template, typename... Args> struct IsSpecializationOf<Template<Args...>, Template> : Bool<true> {
};
template <typename T>
struct IsCString
: Bool<std::is_same<char const *, typename std::decay<T>::type>::value || std::is_same<char *, typename std::decay<T>::type>::value> {
};
template <typename T> struct IsString : Bool<IsCString<T>::value || IsSpecializationOf<T, std::basic_string>::value> {
};
/// \cond
namespace Detail {
// allow ADL with custom begin/end

@ -31,3 +31,15 @@ static_assert(IsIteratable<vector<int>>::value, "IsIterator: positive case");
static_assert(IsIteratable<list<string>>::value, "IsIterator: positive case");
static_assert(IsIteratable<map<string, string>>::value, "IsIterator: positive case");
static_assert(IsIteratable<initializer_list<double>>::value, "IsIterator: positive case");
static_assert(!IsCString<string>::value, "IsCString: negative case");
static_assert(!IsCString<int[]>::value, "IsCString: negative case");
static_assert(!IsCString<int *>::value, "IsCString: negative case");
static_assert(IsCString<char[]>::value, "IsCString: positive case");
static_assert(IsCString<char *>::value, "IsCString: positive case");
static_assert(IsCString<const char *>::value, "IsCString: positive case");
static_assert(!IsString<int *>::value, "IsString: negative case");
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");

Loading…
Cancel
Save