Topic: weird template parameters


Author: "Richard Smith" <richard@ex-parrot.com>
Date: Mon, 24 Jul 2006 11:01:47 CST
Raw View
"Krzysztof Zelechowski" wrote:
> Uzytkownik "Richard Smith" <richard@ex-parrot.com> napisal w wiadomosci
> news:1153244485.683369.55370@75g2000cwc.googlegroups.com...
> >>
> >> My compiler says they are nondeducible and is probably right; however,
> >> N2009
> >> does not contain the word "deducible" at all.
> >
> > Not sure about N2009 -- but as that's only the working draft of C++0x,
> > I don't see how that's relevant.  The current Standard mentions this in
>
> Why irrelevant?  It still has the following statement in 1.1/1:

I meant it's irrelevant in that N2009 is a working draft of the next
version of C++; current compilers aren't generally implementing that.
The correspoding section in ISO/IEC 14882:2003 is what's relevant.

> This International Standard specifies requirements for implementations of
> the C++ programming language.

But as it's only a draft, that statement isn't actually true as it's
not (yet) an International Standard.

> Also I remember being criticized by Mr Miller for quoting the 2003 standard
> because the issue I was referring to had already been fixed.

That's rather different.  The 2003 standard is simply a minor
collection of fixes to the 1998 standard; by contrast, the draft 200x
standard contains much radically new content and is likely to gain much
more.

Anyway, enough of this pedantry...

> > 14.5.4.1/2: "A partial specialization matches a given actual template
> > argument list if the template arguments of the partial specialization
> > can be decuced from the actual template argument list (14.8.2)."
> >
>
> I should have searched "deduced" instead of "deducible", thanks.
> However, 14.5.4.1/2 does not define the word, neither does it define what
> "matching" means.

On the contrary, 14.5.4.1/2's purpose is to define what matching means:
"a partial specialization matches a given actual template argument list
if the template arguments of the partial specialization can be deduced
from the actual tempalte argument list".

--
Richard Smith

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: krixel@qed.pl ("Krzysztof Zelechowski")
Date: Wed, 19 Jul 2006 22:41:26 GMT
Raw View
Uzytkownik "Richard Smith" <richard@ex-parrot.com> napisal w wiadomosci=20
news:1153244485.683369.55370@75g2000cwc.googlegroups.com...
>
> "Krzysztof =AFelechowski" wrote:
>> Is the compiler free to treat the code
>>
>> template<class T> class C {};
>> template<class T> class C<typename T::X> {};
>>
>> as ill-formed?
>
> No; the code is legal.  The partial specialisation will never get used
> as T cannot be deduced from T::X, and a compiler might realise that and
> generate a warning (though I can't immediately think of any that do),

Microsoft Visual C++ (not recommended).

> but the code is legal in just the same way that
>
>  bool foo( std::size_t n ) { return n < 0; }
>
> is legal.
>
>
>> My compiler says they are nondeducible and is probably right; however,=
=20
>> N2009
>> does not contain the word "deducible" at all.
>
> Not sure about N2009 -- but as that's only the working draft of C++0x,
> I don't see how that's relevant.  The current Standard mentions this in

Why irrelevant?  It still has the following statement in 1.1/1:


This International Standard specifies requirements for implementations of=
=20
the C++ programming language.


Also I remember being criticized by Mr Miller for quoting the 2003 standa=
rd=20
because the issue I was referring to had already been fixed.

> 14.5.4.1/2: "A partial specialization matches a given actual template
> argument list if the template arguments of the partial specialization
> can be decuced from the actual template argument list (14.8.2)."
>

I should have searched "deduced" instead of "deducible", thanks.
However, 14.5.4.1/2 does not define the word, neither does it define what=
=20
"matching" means.
For example, it is not clear whether C<int const, int const> matches C<T,=
 T=20
const>.
I think it could even make a defect report.

> DR 549 deals with this issue:
>
>  http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#549
>
> --
> Richard Smith
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with=
 ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu   =
 ]
> [              --- Please see the FAQ before posting. ---              =
 ]
> [ FAQ: http://www.comeaucomputing.com/csc/faq.html                     =
 ]
>=20


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: krixel@qed.pl ("Krzysztof elechowski")
Date: Tue, 18 Jul 2006 15:18:55 GMT
Raw View
Is the compiler free to treat the code

template<class T> class C {};
template<class T> class C<typename T::X> {};

as ill-formed?  I was unable to find anything in the standard to prevent
such Prologuization.

And what about

template<class T> class C<int [sizeof(T)]> {};

?

My compiler says they are nondeducible and is probably right; however, N2009
does not contain the word "deducible" at all.

Chris


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Richard Smith" <richard@ex-parrot.com>
Date: Tue, 18 Jul 2006 12:45:56 CST
Raw View
"Krzysztof    elechowski" wrote:
> Is the compiler free to treat the code
>
> template<class T> class C {};
> template<class T> class C<typename T::X> {};
>
> as ill-formed?

No; the code is legal.  The partial specialisation will never get used
as T cannot be deduced from T::X, and a compiler might realise that and
generate a warning (though I can't immediately think of any that do),
but the code is legal in just the same way that

  bool foo( std::size_t n ) { return n < 0; }

is legal.

I can't immediately think of an occasion when it might be useful to do
this (the specialisation example, not the unsigned comparison), but I
wouldn't be particularly surprised if it had some use.

> And what about
>
> template<class T> class C<int [sizeof(T)]> {};

Interesting.  I think that should compile but never get used (for the
same reasons as the previous example); Comeau disagrees with me,
though:

  error: template parameter "T" is not used in template
         argument list of class template "C<int [sizeof(T)]>"
    template<class T> class C<int [sizeof(T)]> {};

At the very least, I'd say Comeau's error is misleading -- patently T
is used in "int [sizeof(T)]", whether it's used relevantly is another
matter.  Gcc is happy with the code.

> My compiler says they are nondeducible and is probably right; however, N2009
> does not contain the word "deducible" at all.

Not sure about N2009 -- but as that's only the working draft of C++0x,
I don't see how that's relevant.  The current Standard mentions this in
14.5.4.1/2: "A partial specialization matches a given actual template
argument list if the template arguments of the partial specialization
can be decuced from the actual template argument list (14.8.2)."

DR 549 deals with this issue:

  http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#549

--
Richard Smith


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]