Topic: template" keyword overloaded too much
Author: Alberto Barbati <AlbertoBarbati@libero.it>
Date: Tue, 31 May 2005 11:55:41 CST Raw View
Krzysztof Koziarz wrote:
> In a version of C++ that I use, "template" means many conceptually different
> things. I just mention examples of simple class templates here for
> simplicity:
>
> 1).Ordinary template declaration:
> template <typename A, typename B> class example {...};
> 2).Template specialization:
> template <typename A> class example<A, int> {...};
> 3).Explicit instatiation:
> template class example<int, int>;
>
> Adding inherittance or function templates will long parameter list would
> make it even harder to read at a glance to further prove my point which
> follows.
>
> IMO, those concepts are semantically different enough to warrant different
> keywords. Why is it so hard to change the syntax of 2) & 3) into sth like:
>
> 2a) specialize <typename A> class example<A, int> {...};
> 3a) instantiate class example<int, int>;
>
> Per current status, by overusing of "template", C++ is very inconsistent
> with its early constructs, when different keywords "struct" & "class" had
> been introduced to depict the same concept of user defined aggregate type.
>
> I know it's now impossible to replace all instances of
> "struct [...] {"
> with
> "class [...] {public:"
> to get rid of the redundant "struct" keyword (or vice versa), but how about
> inroducing new "specialize" & "instantiate" keywords and deprecate the
> (over)use of "template"?
>
I like the current use of the template keyword and I don't feel the urge
to change that. It's true that the concept of declaration,
specialization and instantiation are semantically different, but they
are strongly related because all operate onto the same kind of object,
that is: templates. IMHO, using three different keywords would confuse
people (especially newbies) even more than the current syntax, because
the strong relationship between the three concepts would no longer be
self-evident.
There's also a more estetic argument against your proposal. If you
followed the past discussions about "class template vs. template class"
you should know that what you specialize is a class template, but in:
specialize <typename A> class example<A, int> {...};
it looks like you are going to specialize a (template) class, which is
non-sensical.
Just my thought,
Alberto
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: petebecker@acm.org (Pete Becker)
Date: Tue, 31 May 2005 16:57:05 GMT Raw View
Krzysztof Koziarz wrote:
>
> IMO, those concepts are semantically different enough to warrant different
> keywords. Why is it so hard to change the syntax of 2) & 3) into sth like:
>
> 2a) specialize <typename A> class example<A, int> {...};
> 3a) instantiate class example<int, int>;
>
It's not hard at all:
#define specialize template
#define instantiate template
That way you can experiment with variations on this notation until
you're happy with it, or until you decide it's more trouple than it's
worth, and if you like it, you can encourage others to try it and,
eventually, propose it for the standard.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: chriskoziarz@ozemail.com.au ("Krzysztof Koziarz")
Date: Tue, 24 May 2005 17:57:59 GMT Raw View
In a version of C++ that I use, "template" means many conceptually different
things. I just mention examples of simple class templates here for
simplicity:
1).Ordinary template declaration:
template <typename A, typename B> class example {...};
2).Template specialization:
template <typename A> class example<A, int> {...};
3).Explicit instatiation:
template class example<int, int>;
Adding inherittance or function templates will long parameter list would
make it even harder to read at a glance to further prove my point which
follows.
IMO, those concepts are semantically different enough to warrant different
keywords. Why is it so hard to change the syntax of 2) & 3) into sth like:
2a) specialize <typename A> class example<A, int> {...};
3a) instantiate class example<int, int>;
Per current status, by overusing of "template", C++ is very inconsistent
with its early constructs, when different keywords "struct" & "class" had
been introduced to depict the same concept of user defined aggregate type.
I know it's now impossible to replace all instances of
"struct [...] {"
with
"class [...] {public:"
to get rid of the redundant "struct" keyword (or vice versa), but how about
inroducing new "specialize" & "instantiate" keywords and deprecate the
(over)use of "template"?
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.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (Llewelly)
Date: Thu, 26 May 2005 15:54:47 GMT Raw View
chriskoziarz@ozemail.com.au ("Krzysztof Koziarz") writes:
> In a version of C++ that I use, "template" means many conceptually different
> things. I just mention examples of simple class templates here for
> simplicity:
>
> 1).Ordinary template declaration:
> template <typename A, typename B> class example {...};
> 2).Template specialization:
> template <typename A> class example<A, int> {...};
> 3).Explicit instatiation:
> template class example<int, int>;
Get used to it. :-) C++ is filled with keywords that have at least as
many uses. e.g., 'namespace' is not used for just delcaring a
namespace - it's used for using directives and namespace aliases
as well.
void has at least 3 distinct uses. static has 3,4 or even 5 depending
on what argument you follow.
And the proposals presented to the committee show strong tendency to
re-use existing keywords instead of adding new ones; several
proposals suggest re-using 'auto', and the modules proposal
re-uses 'namespace'.
>
> Adding inherittance or function templates will long parameter list would
> make it even harder to read at a glance to further prove my point which
> follows.
>
> IMO, those concepts are semantically different enough to warrant different
> keywords. Why is it so hard to change the syntax of 2) & 3) into sth
> like:
Good or bad I don't know, but if that was done for other features that
might need it, C++ would quickly gain many new keywords.
*if* - I say - I don't believe a proposal like this has any hope of
gaining comittee proposal.
>
> 2a) specialize <typename A> class example<A, int> {...};
> 3a) instantiate class example<int, int>;
>
> Per current status, by overusing of "template", C++ is very inconsistent
> with its early constructs, when different keywords "struct" & "class" had
> been introduced to depict the same concept of user defined aggregate type.
>
> I know it's now impossible to replace all instances of
> "struct [...] {"
> with
> "class [...] {public:"
> to get rid of the redundant "struct" keyword (or vice versa), but how about
> inroducing new "specialize" & "instantiate" keywords and deprecate the
> (over)use of "template"?
[snip]
IMO, the only bad thing about your proposal is that the anti-keyword
people would spend an appalling amount of energy attacking it. I'd
rather see that energy spent on other things.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: "Marcus" <yuu@yyhmail.com>
Date: 26 May 2005 23:00:27 GMT Raw View
"Krzysztof Koziarz" escreveu:
> In a version of C++ that I use, "template" means many conceptually different
> things. I just mention examples of simple class templates here for
> simplicity:
>
> 1).Ordinary template declaration:
> template <typename A, typename B> class example {...};
> 2).Template specialization:
> template <typename A> class example<A, int> {...};
> 3).Explicit instatiation:
> template class example<int, int>;
Once i wondered why "explicit instantiation" isn't performed this way:
explicit template class example<int, int>;
It's very logical (neat!) and uses an existing keyword. But i'm not
sure it's a good idea because the old way would need to be supported
along with the new form, making the language more confusing (exactly
the opposite effect!). If only this were a library change...
Anyway, it's not that hard to learn that "'template' not followed by
'<' means explicit instantiation". But specialization is a little
harder...
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]