I have a function that I want to create in a template, at the moment I have two different versions for std::string and std::wstring .
The function (truncated) looks like this:
template <class T, class _Tc> std::vector<T> TokenizeArgs(const T& in) { const T tofind = T("\"' "); .. do stuff .. }
T is either std::string or std::wstring , and _Tc is either char or wchar_t . I'm having a problem getting constant strings that I define to work in the template version. The above code works for std::string , but not for std::wstring , because there is no constructor for std::wstring that accepts a char* array. Normally, to fix this, I would declare a constant string as const T tofind = L"\"' " , but then it would not work with std::string .
I don’t have much experience with templates, so I really don’t know how to fix this problem.
source share