dimanche 22 février 2015

How can I make a function work for both string and wstring?

If I want a function like the following to work on basic_string and basic_string what should I do? Note that it has to change wchar_t in the unordered map.



bool isUnique(wstring s)
{
if (s.size() <= 1)
{
return true;
}
unordered_map<wchar_t, bool> charSeen;
for (int i = 0; i < s.size(); i++)
{
if (!charSeen[s[i]])
{
charSeen[s[i]] = true;
}
else
{
return false;
}
}
return true;
}
int main(int argc, char *argv[]) {
cout << isUnique(L"فعه");
return 0;
}

Aucun commentaire:

Enregistrer un commentaire