C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using string literals as compile time identifiers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Olaf Krzikalla
Guest





PostPosted: Mon Jun 19, 2006 6:56 pm    Post subject: Using string literals as compile time identifiers Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.