how to define string_cast<std::string>( std::wstring)?

Hi,

I need to define a template function that can be specialize for changing strings to wstrings and viceversa, like so:

1
2
3
4
wstring x;
string b = string_cast<std::string>(x);

wstring y = string_cast<std::wstring>(b);


seems so easy!!!

How about this:

1
2
3
4
5
6
7
8
9
10
11
12
13
template<typename T, typename U>
T string_cast(const U& u);


template<>
std::string string_cast<std::string>(const std::wstring &u) {
    return utf16ToUtf8(u);
}

template<>
std::wstring string_cast<std::wstring>(const std::string& u) {
    return utf8ToUtf16(u);
}


It seems to work! Any other implementation ideas?
Topic archived. No new replies allowed.