How can I do the following but easier? I'm templating a class but I want it so that if typename T is of a literal type such as a string or char, then it can use the following member-function. If not then it cannot use it. I've been using typeid to tell whether one is a char or a string or a non-literal type. But it does not work since I cannot do it for both at the same time unless I overload the function. Is there any other way? I do not want to have to make a whole new templated class specialized for chars and strings, This is currently what I have:
template<typename T>
bool CustomType<T>::Contains(T LiteralType, bool CaseSensitive)
{
if ((typeid(T).name() == typeid(std::string).name()) || (typeid(T).name() == typeid(char).name()))
{
std::vector<T> Temp = TypeData; //Create temporary type so the original doesn't change.
if (!CaseSensitive)
{
if (typeid(T).name() == typeid(char).name()) //If it is a char..
LiteralType = tolower(LiteralType);
else
for (size_t I = 0; I < LiteralType.length(); I++)
LiteralType[I] = tolower(LiteralType[I]);
if (typeid(T).name() == typeid(char).name()) //If it is a char..
for (size_t I = 0; I < Temp.size(); I++)
Temp[I] = tolower(Temp[I]);
else
for (size_t I = 0; I < Temp.size(); I++)
for (size_t J = 0; J < Temp[I].size(); J++)
Temp[I][J] = tolower(Temp[I][J]);
}
for (size_t I = 0; I < Temp.size(); I++) //For both of them.
{
if (Temp[I] == LiteralType)
return true;
}
}
return false;
}