I’ve got a function I’m wanting to template, at the moment I have two different versions for std::string and std::wstring.
The function (stripped down) is 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 an issue getting the constant strings 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 which takes a char* array. Normally to fix this I’d declare the constant string as const T tofind = L"\"' ", but then it wouldn’t work with std::string.
I don’t have much experience with templates and so I don’t really know how to fix this issue.
You can move the const creation into its own factory function and specialize the function for
stringandwstringseperately.