 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Olaf Krzikalla Guest
|
Posted: Mon Jun 19, 2006 6:56 pm Post subject: Using string literals as compile time identifiers |
|
|
Hi,
I start with the intended usage:
--snip--
// no C++:
template<const char* const P>
const char* const get_text ()
{
static const char* const result = lookup_translation (P);
return result;
}
#define GETTEXT(C) get_text<C>()
void foo()
{
std::cout << GETTEXT ("Hello world"); // prints a localized version
of "Hello world"
}
--snip--
Well, the above doesn't compile due to the internal linkage of string
literals. (IMHO it's a good example of why string literals should be
allowed as template arguments.)
But is there any other way to achieve the desired effect automagically?
That is to trigger the lookup only once for each literal while the
macro (or whatever) can be used as a normal expression.
[note:
The following doesn't work due to 7.1.2.4:
inline const char* const get_text (const char* const P)
{
static const char* const result = lookup_translation (P);
return result;
}
]
Do I really have to advise my co-workers to rewrite 'foo', whenever
speed is an issue (and that is always the case):
void foo()
{
static const char* const think_about_yet_another_name = GETTEXT
("Hello world");
std::cout << think_about_yet_another_name;
}
?
Best regards
Olaf Krzikalla
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|