Topic: Template Syntax
Author: Scott Meyers <smeyers@netcom.com>
Date: 1996/04/10 Raw View
I was under the impression that the use of a template name inside the
definition of a class template was implicitly considered to be qualified
by the template parameter(s). For example, I thought that in
template <class T>
class Array {
public:
Array operator=(const Array& rhs);
...
};
the declaration of operator= was legal, because the use of the token
"Array" as a return type and a paramter was implicitly treated as if it
were "Array<T>." Many compilers accept this, but I'm told that several
reject it, and I can't find language in the January DWP that allows it.
1. Is the above syntax valid, or must "Array" always be specified as
"Array<T>"?
2. If the above is not valid, was it valid at one time (post-ARM)?
If so, when and why was it disallowed?
Thanks,
Scott
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/04/11 Raw View
>>>>> "SM" == Scott Meyers <smeyers@netcom.com> writes:
[...]
SM> 1. Is the above syntax valid, or must "Array" always be
SM> specified as "Array<T>"?
Yes, it's valid. For the January DWP this is explained in
[temp.local] 14.2.1/1 (14.5.1/1 in the Santa Cruz revision
of the templates chapter).
[...]
Daveed
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Rich Paul <rpaul@trcinc.com>
Date: 1996/04/12 Raw View
Scott Meyers wrote:
>
> I was under the impression that the use of a template name inside the
> definition of a class template was implicitly considered to be qualified
> by the template parameter(s). For example, I thought that in
>
> template <class T>
> class Array {
> public:
> Array operator=(const Array& rhs);
> ...
> };
The following is a quote from the January '96 working paper. However, I'm told that
that document is already obsolete ( though I gather it's mostly in the library ...
[ moderator's note: the working paper is updated every four months. The January
version is the latest that has been published, but some changes were made at
the March meeting. -sdc ]
--- BEGIN WP QUOTE ---
1 Within the scope of a class template or a specialization of a template
the name of the template is equivalent to the name of the template
followed by the template-parameters enclosed in <>. [Example: the
constructor for Set can be referred to as Set() or Set<T>(). ] Other
specializations (_temp.spec_) of the class can be referred to by
explicitly qualifying the template name with appropriate template-
arguments. [Example:
template<class T> class X {
X* p; // meaning X<T>
X<T>* p2;
X<int>* p3;
};
template<class T> class Y;
template<> class Y<int> {
Y* p; // meaning Y<int>
};
--end example] [Note: see _temp.param_ for the scope of template-
parameters. ]
--- END WP QUOTE ---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Rich Paul <rpaul@trcinc.com>
Date: 1996/04/12 Raw View
> the declaration of operator= was legal, because the use of the token
> "Array" as a return type and a paramter was implicitly treated as if it
> were "Array<T>." Many compilers accept this, but I'm told that several
> reject it, and I can't find language in the January DWP that allows it.
>
As I implemented the standard string class, I learned that one
of my compilers accepts this, while another rejects it.
MSVC4.0 and Borland 5, respectively. I'd suspect that it a
recently removed language feature, but for portability, I used
this:
template < class charT, class traits, class Allocator >
class basic_string
{
typedef basic_string<charT, traits, Allocator> self;
public:
basic_string ( const self & );
};
The only problem I haven't worked around is that I'd like to
say:
template<class charT, class traits, class Allocator >
self operator + ( const self &lhs, const self &rhs )
{
return self ( lhs )+= rhs;
};
Alas, since there is no scope in which to use the typedef, I'm
stuck with spelling it out ...
Regards,
Rich
(BTW, are you Scott Meyers of More Effective C++ fame? If so,
great job!)
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: jpb@iris8.msi.com (Jan Bielawski)
Date: 1996/04/16 Raw View
In article <199604102351.QAA11178@netcom15.netcom.com> Scott Meyers <smeyers@netcom.com> writes:
<I was under the impression that the use of a template name inside the
<definition of a class template was implicitly considered to be qualified
<by the template parameter(s). For example, I thought that in
<
< template <class T>
< class Array {
< public:
< Array operator=(const Array& rhs);
< ...
< };
<
<the declaration of operator= was legal, because the use of the token
<"Array" as a return type and a paramter was implicitly treated as if it
<were "Array<T>." Many compilers accept this, but I'm told that several
<reject it, and I can't find language in the January DWP that allows it.
Doesn't section 14.2.1 ("Locally declared names") explicitly allow it?
--
Jan Bielawski
Molecular Simulations, Inc. )\._.,--....,'``. | http://www.msi.com
San Diego, CA /, _.. \ _\ ;`._ ,. | ph.: (619) 458-9990
jpb@msi.com fL `._.-(,_..'--(,_..'`-.;.' | fax: (619) 458-0136
--
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]