For pre-C++11 (C++03 and C++98) the T in std::basic_string<T> is in
practice either `char` or `wchar_t` – because it's too much work to
specialize `std::character_traits` for any other type, and without such
specialization std::basic_string<T> is very limited, useless.
So, I suggest you use a macro to define pairs of literals:
#define DEF_LITERAL( name, lit ) \
char const* const bytestr_name = lit; \
wchar_t const* const widestr_name = L # lit; \
template< class Ch ) Ch const* name(); \
char const* name<char>() { return bytestr_name; } \
wchar_t const* name<char>() { return widestr_name; }
Then use like
DEF_LITERAL( baluba, "Real baluba!" )
void foo()
{
wstring s = baluba<wchar_t>();
}
Disclaimer: code not seen by compiler.
Cheers & hth.,
- Alf