Been playing around with this all day, and haven't found a solution I
like yet.
Assuming some initial function:
void foo(std::string& src)
{
src += "some fixed string";
src += bar();
src += "some other fixed string";
src += bar2();
src += "final fixed string";
}
What is the best way to turn this into a templated version that can
work on both std::basic_string<char> AND std::basic_string<wchar_t>?
Basically, I'd like something that looks (something) like:
template <class T>
void foo(std::basic_string<T>& src)
{
src += CVT("some fixed string");
src += bar();
src += CVT("some other fixed string");
src += bar2();
src += CVT("final fixed string";
}
Where CVT is a macro that expands to either the plain string literal
as is, or prepended with 'L' for the wchar_t version. Of course
because macro expansion is done prior to template evaluation, this
isn't directly possible.
I've played around with various options, but most of them produce
absurdly inefficient assembly-code (with various compilers), or just
look plain ugly and don't really make doing the same sort of thing in
the future any great deal easier.
Anyway, any ideas people may have on alternative ways of achieving
this effect are much appreciated!
Dylan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]