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! ]


|