2 replies
I received this e-mail today. I thought it might be of interest:
For standard library template strings I do:
#ifdef _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
Works perfectly and simply extends Microsoft's _Tand TCHAR approach.
by john torjo
Hi,
I quite agree with the above technique for day-to-day programming. However, there are a few drawbacks for generic programming:
- it's Microsoft specific
- it does not scale for generic programming. When doing generic programming, you cannotassume the character type passed to a generic function.
Consider the following:
// should work for 'const char *' strings,
// 'const wchar_t *' strings, etc.
template< class char_type>
int str_length( const char_type * str)
{ /* code */ }
A client of your code might use:
int nLen = str_length( "this is a test"); /* 'const char *' */
OR
int nLen = str_length( L"this is a test"); /* 'const wchar_t *' */
or, even both.
Best,
John
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending