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 15 of 23 Topic 9495 of 9831
Post > Topic >>

Re: String literal as template parameter?

by Alberto Ganesh Barbati <AlbertoBarbati@[EMAIL PROTECTED] > Apr 16, 2008 at 11:43 AM

Daniel Krügler ha scritto:
> On 15 Apr., 05:24, Alberto Ganesh Barbati <AlbertoBarb...@[EMAIL PROTECTED]
>
> wrote:
> 
>> 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.
> 
> I think that this extension proposal goes to far
> and that there exist an alternative given concepts
> to realize the same thing.
> 
> The problem I see is, that this approach might seem
> natural for human tolerant pattern matching, but it
> is not so well-situated for the compiler. It seems
> natural for human beings, because it bases on some
> form of convention: "Just assume that all template
> parameters are non-type parameters and each one has
> the same type and this type must be a character type".

Maybe my exposition was a bit confused. What I meant was only that a
string literal argument is to be replaced with a sequence of character
literal arguments *before* trying to match template argument with
template parameters. That's a simple process that any compiler could do.
So, for example:

   FourCC<"RIF"> is interpreted as FourCC<'R','I','F'>
   FourCC<"RIFF"> is interpreted as FourCC<'R','I','F','F'>
   FourCC<"RIFFF"> is interpreted as FourCC<'R','I','F','F','F'>

the first and third template-ids are ill-formed simply because normal
template parameter matching rules make them so. No additional rule is
needed to get this result. Do you see any problem with that?

On the other hand, if I understand it correctly, the OP's proposal
requires that a string literal argument shall match *only* a template
parameter pack. This has a both advantages and disadvantages, in my
opinion.

> If I understand the current state of the concept proposal
> correctly it should be realizable via a *constrained*
> variadic template:
> 
>     #include <concepts>
> 
>     template <char... s>
>     requires std::True<sizeof...(s) == 4>
>     class FourCC
>     {
>        //...
>     };
> 
> The enforcement to use a non-type variadic template
> is simple to check for the compiler, because this
> form already guarantees a homogeneous sequence.

This solution is correct and valid, however there's no need for concepts
to tackle this particular example with my approach.

Just my opinion,

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:57:58 CDT 2008.