Created
September 16, 2012 08:39
-
-
Save chenshuo/3731612 to your computer and use it in GitHub Desktop.
char and wchar_t in template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template<typename CharT> | |
const CharT* ToString(const char* str, const wchar_t* wstr); | |
template<> | |
const char* ToString<char>(const char* str, const wchar_t* wstr) | |
{ | |
return str; | |
} | |
template<> | |
const wchar_t* ToString<wchar_t>(const char* str, const wchar_t* wstr) | |
{ | |
return wstr; | |
} | |
#define TOSTRING(T, str) ToString<T>(str, L##str) | |
int main() | |
{ | |
std::cout << ToString<char>("Hello", L"World") << std::endl; | |
std::wcout << ToString<wchar_t>("Hello", L"World") << std::endl; | |
std::cout << TOSTRING(char, "Who am I") << std::endl; | |
std::wcout << TOSTRING(wchar_t, "Who am I") << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment