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


|