You can make yourself a macro. First, define a structure that wraps char -choosing:
namespace details { template<typename T> struct templ_text; template<> struct templ_text <char> { typedef char char_type; static const char_type * choose(const char * narrow, const wchar_t * wide, const char16_t* u16, const char32_t* u32) { return narrow; } static char_type choose(char narrow, wchar_t wide, char16_t u16, char32_t u32) { return narrow; } }; template<> struct templ_text < wchar_t > { typedef wchar_t char_type; static const char_type* choose(const char * narrow, const wchar_t * wide, const char16_t* u16, const char32_t* u32) { return wide; } static char_type choose(char narrow, wchar_t wide, char16_t u16, char32_t u32) { return wide; } }; template<> struct templ_text < char16_t > { typedef char16_t char_type; static const char_type* choose(const char * narrow, const wchar_t * wide, const char16_t* u16, const char32_t* u32) { return u16; } static char_type choose(char narrow, wchar_t wide, char16_t u16, char32_t u32) { return u16; } }; template<> struct templ_text < char32_t > { typedef char32_t char_type; static const char_type* choose(const char * narrow, const wchar_t * wide, const char16_t* u16, const char32_t* u32) { return u32; } static char_type choose(char narrow, wchar_t wide, char16_t u16, char32_t u32) { return u32; } }; }
Wrap it in a beautiful macro:
#define TEMPL_TEXT(Ch, txt) details::templ_text<Ch>::choose(txt, L##txt, u##txt, U##txt)
Then your function will be:
template<typename StringType> void hello_string() { StringType result(TEMPL_TEXT(typename StringType::value_type, "Hello")); }
I think that unused copies of the string will be optimized.