Topic: Explicit Specialization of Class Member Templates
Author: giecrilj@stegny.2a.pl ("Kristof Zelechovski")
Date: Tue, 17 Oct 2006 12:33:03 GMT Raw View
Uzytkownik "Tom Widmer" <tom.widmer@googlemail.com> napisal w wiadomosci
news:1161012903.087031.284620@b28g2000cwb.googlegroups.com...
>
>
> On Oct 16, 3:42 pm, giecr...@stegny.2a.pl ("Kristof Zelechovski")
> wrote:
>> An explicit specialization of a member template class should be declared
>> within the class.
>> Chris
>
> This appears to be directly contradicted here:
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#44
>
> That link also implies that such specializations are legal, at least if
> declared at namespace scope. I think that the omission in 14.7.3/1
> described by the OP is a defect.
>
The case is not closed and other views are still possible. The word
"implies" is too strong here, it merely suggests. I do not like the
suggestion myself. No argument has been published in favour of this
construct and there are valid structural arguments against. It breaks the
principle that C++ does not allow code injection unless the class is
specifically designed to host injected code.
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: "Tom Widmer" <tom.widmer@googlemail.com>
Date: Wed, 18 Oct 2006 11:31:18 CST Raw View
"Kristof Zelechovski" wrote:
> The case is not closed and other views are still possible.
But no one has suggested that specialization of member templates is not
or should not be allowed.
The word
> "implies" is too strong here, it merely suggests. I do not like the
> suggestion myself. No argument has been published in favour of this
> construct and there are valid structural arguments against. It breaks the
> principle that C++ does not allow code injection unless the class is
> specifically designed to host injected code.
Surely the omission of member templates of classes from the list was a
strange exception to the general allowance of "code injection" with
templates, via specialization. Or do you think that template
specialization is against the principles of C++?
In any case, see Ganesh's post.
Tom
---
[ 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: giecrilj@stegny.2a.pl ("Kristof Zelechovski")
Date: Thu, 19 Oct 2006 14:42:19 GMT Raw View
Uzytkownik "Tom Widmer" <tom.widmer@googlemail.com> napisal w wiadomosci
news:1161182689.666594.151110@m7g2000cwm.googlegroups.com...
>
> "Kristof Zelechovski" wrote:
>
>> The case is not closed and other views are still possible.
>
> But no one has suggested that specialization of member templates is not
> or should not be allowed.
>
> The word
>> "implies" is too strong here, it merely suggests. I do not like the
>> suggestion myself. No argument has been published in favour of this
>> construct and there are valid structural arguments against. It breaks
>> the
>> principle that C++ does not allow code injection unless the class is
>> specifically designed to host injected code.
>
> Surely the omission of member templates of classes from the list was a
> strange exception to the general allowance of "code injection" with
> templates, via specialization. Or do you think that template
> specialization is against the principles of C++?
>
An explicit specialization of a template class member if a nontemplate class
is code injection into the nontemplate class unless the class declares the
specialization as well.. Therefore it is against the principle that once a
class definition is closed, it cannot be extended (without creating a
derivation via inheritance) and thus it should not be allowed IMHO.
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: "Tom Widmer" <tom.widmer@googlemail.com>
Date: Tue, 24 Oct 2006 11:26:10 CST Raw View
On Oct 19, 3:42 pm, giecr...@stegny.2a.pl ("Kristof Zelechovski")
wrote:
> > Surely the omission of member templates of classes from the list was a
> > strange exception to the general allowance of "code injection" with
> > templates, via specialization. Or do you think that template
> > specialization is against the principles of C++?
> An explicit specialization of a template class member if a nontemplate class
> is code injection into the nontemplate class unless the class declares the
> specialization as well.. Therefore it is against the principle that once a
> class definition is closed, it cannot be extended (without creating a
> derivation via inheritance) and thus it should not be allowed IMHO.
That about "code injection" into class template specializations (which
are, of course, classes)? e.g.:
template<>
template<>
void A<int>::f<int>();
Why should it be different for a class that wasn't generated from a
class template? Or are you advocating disallowing
out-of-class(-template)-definition specialization of member templates
full stop? (currently it isn't allowed in-class-template-definition
either, so this would actually forbid specializations of members
completely, but that's a separate issue)
The reason to always allow it is that the writer of a class (or class
template) does not know in advance, in general, the complete set of
types with which his member template will be instantiated, and
therefore cannot know the full set of explicit specializations of the
member template that will be required. You can also prevent explicit
specialization of the specializations that you don't want to be
modified by explicitly instantiating them in a library.
---
[ 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: "Greg Herlihy" <greghe@pacbell.net>
Date: Sun, 15 Oct 2006 20:58:47 CST Raw View
Can a member template of a class be explicitly specialized? 14.7.3
enumerates the kinds of templates that can be explicitly specialized
(which includes a member function template of a class template) but
both a "member class template of a class" and "member function template
of a class" are notably absent from this list. Is this omission
intentional?
If the omission is intentional, then this text from the same section:
"An explicit specialization shall be declared in the namespace of which
the template is a member, or, for member templates, in the namespace of
which the enclosing class or enclosing class template is a member."
seems to imply otherwise. The phrase "enclosing class or enclosing
class template" suggests that it is possible to specialize a member
template of a class. After all, there is no point in mentioning an
"enclosing class" if it is not possible for a member template explicit
specialization to have an enclosing class.
Greg
---
[ 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: giecrilj@stegny.2a.pl ("Kristof Zelechovski")
Date: Mon, 16 Oct 2006 14:42:25 GMT Raw View
An explicit specialization of a member template class should be declared=20
within the class. The description in the standard is erratic. (I cannot=
=20
say it is erroneous because I do not know the author's intent; but it is=20
obviously erratic as it contradicts itself and common sense).
Chris
Uzytkownik "Greg Herlihy" <greghe@pacbell.net> napisal w wiadomosci=20
news:1160960278.852526.65840@k70g2000cwa.googlegroups.com...
> Can a member template of a class be explicitly specialized? =A714.7.3
> enumerates the kinds of templates that can be explicitly specialized
> (which includes a member function template of a class template) but
> both a "member class template of a class" and "member function template
> of a class" are notably absent from this list. Is this omission
> intentional?
>
> If the omission is intentional, then this text from the same section:
>
> "An explicit specialization shall be declared in the namespace of which
> the template is a member, or, for member templates, in the namespace of
> which the enclosing class or enclosing class template is a member."
>
> seems to imply otherwise. The phrase "enclosing class or enclosing
> class template" suggests that it is possible to specialize a member
> template of a class. After all, there is no point in mentioning an
> "enclosing class" if it is not possible for a member template explicit
> specialization to have an enclosing class.
>
> Greg
>
>
> ---
> [ 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: "Tom Widmer" <tom.widmer@googlemail.com>
Date: Mon, 16 Oct 2006 10:43:47 CST Raw View
On Oct 16, 3:42 pm, giecr...@stegny.2a.pl ("Kristof Zelechovski")
wrote:
> An explicit specialization of a member template class should be declared
> within the class.
> Chris
This appears to be directly contradicted here:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#44
That link also implies that such specializations are legal, at least if
declared at namespace scope. I think that the omission in 14.7.3/1
described by the OP is a defect.
Tom
---
[ 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: Alberto Ganesh Barbati <AlbertoBarbati@libero.it>
Date: Mon, 16 Oct 2006 11:08:57 CST Raw View
Greg Herlihy ha scritto:
> Can a member template of a class be explicitly specialized? 14.7.3
> enumerates the kinds of templates that can be explicitly specialized
> (which includes a member function template of a class template) but
> both a "member class template of a class" and "member function template
> of a class" are notably absent from this list. Is this omission
> intentional?
Well... Paragraph 14.7.3/1 sounds really ill-worded to me. It
enumerates a list of cases that "can be declared by a declaration
introduced by template<>". The use of "can" is unfortunate, IMHO. The
paragraph fails to specify:
1) whether the list is exhaustive
2) whether there may be a different syntax to declare templates that
aren't on the list
3) whether there may be a different syntax to define templates (both in
the list and not)
> If the omission is intentional, then this text from the same section:
>
> "An explicit specialization shall be declared in the namespace of which
> the template is a member, or, for member templates, in the namespace of
> which the enclosing class or enclosing class template is a member."
>
> seems to imply otherwise.
Yup. There's more. If the list in 14.7.3/1 were exhaustive, then we
would have a plain contradiction with 14.7/3, which says: "An explicit
specialization may be declared for a function template, a class
template, a member of a class template or a member template. An explicit
specialization declaration is introduced by template<>. In an explicit
specialization declaration for a class template, a member of a class
template or a class member template, the name of the class that is
explicitly specialized shall be a template-id. In the explicit
specialization declaration for a function template or a member function
template, the name of the function or member function explicitly
specialized may be a template-id."
Thus 14.7/3 clearly allows the possibility to specialize member
templates of a (non-template) class. Moreover, it makes 14.7.3/1
redundant, as the latter does not seem to add any new information, while
its apparent incompleteness creates confusion.
Just my two eurocent,
Ganesh
---
[ 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 ]