Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: String lite...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 23 Topic 9495 of 9831
Post > Topic >>

Re: String literal as template parameter?

by Alberto Ganesh Barbati <AlbertoBarbati@[EMAIL PROTECTED] > Apr 14, 2008 at 09:24 PM

Sean Hunt ha scritto:
> 
> Yeah. This is a good idea. It doesn't take a lot of wording either:
> 
> Under [temp.arg.nontype], paragraph 1, add "a string literal" as
> another element of the list. Replace paragraph 2 with "A string
> literal shall only appear as the last template parameter (including
> default parameters)." Add a new paragraph that says "A string literal
> non-type template parameter is intepreted as a series of character
> literals, each representing one character from the string (in order)
> and becoming a separate template parameter, with a final '\0' as the
> last parameter (so that the number of resultant character literals is
> one greater than the number of characters in the string literal)." and
> add some appropriate example. Probably didn't get the standardese
> quite right, but the point is that it is quite a minor change.

I agree that this is a great idea and, although I am no language lawyer,
the proposed wording seems a very good base to start with.

I would leave out the '\0' terminator for several reasons: 1) for
consistency with the extensible literal proposal, 2) because the list of
characters is not stored in memory, so it won't be passed to functions
expecting a null-terminated string anyway, 3) a null terminator can
easily be appended, but removing it requires non-trivial
meta-programming, 4) applying the sizeof... operator to the argument
pack would return the intuitively correct length of the literal.

I also don't find it compelling to require that the string literal
appears as the last argument. Although I understand the intent, I don't
think the requirement provides a true simplification for the
implementor, yet it may limit some possibly valid uses. Moreover, if we
find the proper wording, we might even allow string literals to match
non-variadic templates. For example, consider a  library component
implementing a FourCC (http://en.wikipedia.org/wiki/Fourcc):

   template <char A, char B, char C, char D> class FourCC

   FourCC<"RIFF"> riff; // ok: maps to FourCC<'R', 'I', 'F', 'F'>

isn't that neat? Of course, FourCC<"RIF"> and FourCC<"RIFFF"> would be
ill-formed. The key is to simply replace the literal with the sequence
of single characters and then apply the "normal" template machinery.

What do you think?

Ganesh

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 23 Posts in Topic:
String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-12 12:09:19 
Re: String literal as template parameter?
Looney <hardy_melbourn  2008-04-13 12:45:53 
Re: String literal as template parameter?
Mathias Gaunard <loufo  2008-04-13 18:21:48 
Re: String literal as template parameter?
Brendan <catphive@[EMA  2008-04-13 18:21:13 
Re: String literal as template parameter?
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-13 18:23:27 
Re: String literal as template parameter?
Sean Hunt <rideau3@[EM  2008-04-14 10:43:12 
Re: String literal as template parameter?
mark.zaytsev@[EMAIL PROTE  2008-04-14 13:13:15 
Re: String literal as template parameter?
Mathias Gaunard <loufo  2008-04-14 21:25:44 
Re: String literal as template parameter?
Alberto Ganesh Barbati &l  2008-04-14 21:24:25 
Re: String literal as template parameter?
Alberto Ganesh Barbati &l  2008-04-14 21:24:01 
Re: String literal as template parameter?
Alberto Ganesh Barbati &l  2008-04-14 21:24:40 
Re: String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-15 12:43:13 
Re: String literal as template parameter?
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-15 23:19:28 
Re: String literal as template parameter?
David Peklak <dpeklak@  2008-04-15 23:22:35 
Re: String literal as template parameter?
Alberto Ganesh Barbati &l  2008-04-16 11:43:13 
Re: String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-17 19:35:09 
Re: String literal as template parameter?
Alberto Ganesh Barbati &l  2008-04-18 05:09:08 
Re: String literal as template parameter?
Sean Hunt <rideau3@[EM  2008-04-18 06:13:18 
Re: String literal as template parameter?
Bart van Ingen Schenau &l  2008-04-18 17:19:53 
Re: String literal as template parameter?
gpderetta <gpderetta@[  2008-04-18 17:20:48 
Re: String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-19 01:39:07 
Re: String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-19 02:01:57 
Re: String literal as template parameter?
Piotr Rak <piotr.rak@[  2008-04-19 02:02:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:51:19 CDT 2008.