Topic: Differentiate between a template class and class template


Author: richard@ex-parrot.com (Richard Smith)
Date: Fri, 29 Oct 2004 15:23:53 +0000 (UTC)
Raw View
Ben Hutchings <ben-public-nospam@decadentplace.org.uk> wrote in message
news:<slrncnhvur.fqi.ben-public-nospam@decadentplace.org.uk>...
> Richard Smith wrote:
>  > Francis Glassborow wrote:
>  > >
>  > > A template class is whatever you make it mean. Personally I do not use
>  > > the term, but if I did it would be to refer to a class that had been
>  > > generated from a template.
>  >
>  > I don't think it can mean whatever you want, as the term "template
>  > class" appears in several places in the Standard.
>  >
>  > In the sections on the Standard Library, many of the sections have
>  > headings like "Template class vector" [23.2.4].
>  <snip>
>  > So it looks like "template class" is being used in different places in
>  > the standard to mean a class that is an instantiation of a class
>  > template, and a synonym for class template.
>
> You must be reading the 1998 standard.  This was corrected in the
> 2003 version in response to defect report 105

You're quite correct.  I guess I must have inadvertently searched the 1998
copy.

Sorry for the confusion.

--
Richard Smith

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Ben Hutchings <ben-public-nospam@decadentplace.org.uk>
Date: Sat, 23 Oct 2004 18:13:12 +0000 (UTC)
Raw View
Richard Smith wrote:
 > Francis Glassborow wrote:
 > >
 > > A template class is whatever you make it mean. Personally I do not use
 > > the term, but if I did it would be to refer to a class that had been
 > > generated from a template.
 >
 > I don't think it can mean whatever you want, as the term "template
 > class" appears in several places in the Standard.
 >
 > In the sections on the Standard Library, many of the sections have
 > headings like "Template class vector" [23.2.4].
<snip>
 > So it looks like "template class" is being used in different places in
 > the standard to mean a class that is an instantiation of a class
 > template, and a synonym for class template.

You must be reading the 1998 standard.  This was corrected in the
2003 version in response to defect report 105; now "template class" is
only used to mean an instantiation of a class template, and similarly
for "template function".

--
Ben Hutchings
If you seem to know what you are doing, you'll be given more to do.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: rmaddox@isicns.com (Randy Maddox)
Date: Sat, 23 Oct 2004 18:13:12 +0000 (UTC)
Raw View
richard@ex-parrot.com (Richard Smith) wrote in message
news:<1a0929fa.0410190319.228e2651@posting.google.com>...
> Francis Glassborow wrote:
>  >
>  > A template class is whatever you make it mean. Personally I do not use
>  > the term, but if I did it would be to refer to a class that had been
>  > generated from a template.
>
> I don't think it can mean whatever you want, as the term "template
> class" appears in several places in the Standard.
>
> In the sections on the Standard Library, many of the sections have
> headings like "Template class vector" [23.2.4].
>
> The term has also been used in 17.1.18 when a traits class is defined
> as "a class that encapsulates a set of types and functions necessary
> for template classes and template functions to manipulate objects of
> types for which they are instantiated".  In this case taking template
> class to mean a class which is an instantiation of a class template
> seems reasonable.
>
> In a number of other places the term is used synonymously with "class
> template"; for instance, 26.2/1, "the header <complex> defines a
> template class, and numberous functions ...".  The header *actually*
> defines one class template, three explicit specialisations of that
> class template.  24.5/1 is another such example.
>
> Additionally, the term "non-template class" is used in several places
> (14.5.3/6, 14.6.5/2, and twice in the hilarious 14.7.3/7); in these
> contexts it seems to mean a class which is not an instantiation of a
> class template, suggesting that "template class" should mean a class
> which is an instantiation of a class template.
>
> So it looks like "template class" is being used in different places in
> the standard to mean a class that is an instantiation of a class
> template, and a synonym for class template.
>
> --
> Richard Smith
>

Are you perhaps looking at an old version of the Standard?

The current version, ISO/IEC 14882:2003(E), contains but a single
occurrence of the term "template class".  In 23.3.5/2 we find:  "The
template class bitset<N> describes an object that can store a sequence
consisting of a fixed number
of bits, N."  Other than that it appears that all of your referenced
uses above have been changed from template class to class template.

Randy.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Sharad Kala <no_spam.sharadk_ind@yahoo.com>
Date: Sat, 16 Oct 2004 16:58:02 +0000 (UTC)
Raw View

"james" <james_merch@hotmail.com> wrote in message

> I had an interview a few days ago and the interviewer
> asked me this C++ question:
> "Differentiate between a template class and class template?"
> Can anyone explain me the differences?

Is there anything like "template class" ? AFAIK, no. The correct term to be
used is "class template". But the irony is that while writing a class
template you write  "template class"
template <class MyType>

:-)

Sharad



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Francis Glassborow <francis@robinton.demon.co.uk>
Date: Sat, 16 Oct 2004 16:58:02 +0000 (UTC)
Raw View
In article <e2ef22db.0410131551.1c43209e@posting.google.com>, james
<james_merch@hotmail.com> writes
>Hi guys,
>
>I had an interview a few days ago and the interviewer
>asked me this C++ question:
>"Differentiate between a template class and class template?"
>Can anyone explain me the differences?

A template class is a template from which class definitions can be
generated (just as a function template is a template from which
functions can be generated.)

{Moderator's note: I'm pretty sure Francis meant the next sentence
to begin with "A class template..." -mod/dk}

A template class is whatever you make it mean. Personally I do not use
the term, but if I did it would be to refer to a class that had been
generated from a template.


--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Tom Widmer <tom_usenet@hotmail.com>
Date: Sat, 16 Oct 2004 16:58:02 +0000 (UTC)
Raw View
On Thu, 14 Oct 2004 22:02:39 +0000 (UTC), james_merch@hotmail.com
(james) wrote:

>
>Hi guys,
>
>I had an interview a few days ago and the interviewer
>asked me this C++ question:
>"Differentiate between a template class and class template?"
>Can anyone explain me the differences?

A template class is generally an informal name for what the C++
standard calls a class template. IOW, they are the same thing.
However, "template class" is misleading, since it leads to the
impression that a class template is actually a class, whereas in fact
it is a template for making classes. However, since "template class"
isn't a formally defined term, they might be using it to refer to a
class template specialization, but I don't think that's the most
common usage.

Although the standard doesn't use "template class" at all, it does use
the phrase "non-template class", but, to be honest, I think that's not
really a correct usage - by definition, a class isn't a class template
in any case, so "non-template class" == "class".

Tom

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Graeme Prentice <gprenz@hotmail.com>
Date: Sat, 16 Oct 2004 16:58:03 +0000 (UTC)
Raw View
On Thu, 14 Oct 2004 22:02:39 +0000 (UTC), james wrote:

>
>Hi guys,
>
>I had an interview a few days ago and the interviewer
>asked me this C++ question:
>"Differentiate between a template class and class template?"
>Can anyone explain me the differences?


"class template" refers to the definition of a class that is a template.
A class template is a template -  it's a "pattern"
e.g.
template <typename T> class abc { T x; };

abc is the name of a template  - a class template.  It is not a class.

abc<int> is the name of a class, it is not a template but is a class
generated from a template -  a class generated from a template is
sometimes referred to as a template class.  A class generated from a
template has an official name of "class template specialization".

abc<int> is also called a template-id  i.e. a template-id is the name of
a template followed by a list of one or more template arguments between
the angle brackets.  A template-id identifies a specialization of a
template.

In my opinion this is a semi trick question.  If you search on
groups.google.com you'll get 12,600 hits for "class template" and 72,800
for "template class"  - however the "template class" search picks up
template <class ...  If you search for subject = template class or class
template, you get equal numbers and you can soon see that the terms are
used interchangeably.

The 2003 revision of the C++ standard (TC1) uses the term "class
template" 475 times and "template class" about 4 or 5 times.
The 1998 C++ standard uses "template class" approx 215 times and "class
template" 255 times.
i.e. the 2003 revision of the C++ standard changed many instances of
"template class" to "class template".  Similarly some instances
"template function" were changed to "function template".

If you have a copy of C++ templates by Vandevoord and Josuttis, they
point out that "template class" is used to mean at least three different
things
- as a synonym for class template
- to refer to classes generated from templates
- to refer to classes with a name that is a template-id

The book says it avoids the term "template class" because of the
multiple meanings  -  however in every day usage, it's usually clear
what is meant when "template class" is used.

In the C++ standard, the correct terminology can matter quite a lot
(especially regarding functions) but in every day usage the meaning of
"template class" is usually clear from the context.

Graeme

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Sumit Rajan <sumitrajan@yahoo.com>
Date: Sat, 16 Oct 2004 16:58:02 +0000 (UTC)
Raw View
james wrote:
> Hi guys,
>
> I had an interview a few days ago and the interviewer
> asked me this C++ question:
> "Differentiate between a template class and class template?"
> Can anyone explain me the differences?
>

In case of you have access to a copy of "C++ Templates: The Complete
Guide" you may like to look up Section 7.1("Class Template" or "Template
Class"?).

--
Sumit Rajan <sumit DOT rajan AT gmail DOT com>

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Gabriel Dos Reis <gdr@cs.tamu.edu>
Date: Mon, 18 Oct 2004 13:40:05 +0000 (UTC)
Raw View
Sharad Kala <no_spam.sharadk_ind@yahoo.com> writes:

| "james" <james_merch@hotmail.com> wrote in message
|
| > I had an interview a few days ago and the interviewer asked me this
| > C++ question:
| > "Differentiate between a template class and class template?"
| > Can anyone explain me the differences?
|
| Is there anything like "template class" ? AFAIK, no. The correct term
| to be used is "class template".

That term was used in the earlier drafts of the C++ standard text.  It
has been changed (I think)  between CD2 and the final draft.  It used to
mean a class generated from a class template.  It can lead to
interesting sentences :-)

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Graeme Prentice <gprenz@hotmail.com>
Date: Mon, 18 Oct 2004 13:40:06 +0000 (UTC)
Raw View
On Sat, 16 Oct 2004 16:58:03 +0000 (UTC), Graeme Prentice wrote:

>
>If you have a copy of C++ templates by Vandevoord and Josuttis, they
>point out that "template class" is used to mean at least three
>different things
>- as a synonym for class template
>- to refer to classes generated from templates
>- to refer to classes with a name that is a template-id
>
>The book says it avoids the term "template class" because of the
>multiple meanings  -  however in every day usage, it's usually clear
>what is meant when "template class" is used.

oops, I didn't quite mean that - the book doesn't say both of those
things in the last sentence above.  The book says it avoids the term
"template class" because of its imprecision.  The second part of the
above is my opinion.

Graeme

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Graeme Prentice <gprenz@hotmail.com>
Date: Mon, 18 Oct 2004 17:41:20 +0000 (UTC)
Raw View
On Sat, 16 Oct 2004 16:58:02 +0000 (UTC), Francis Glassborow wrote:

>
>In article <e2ef22db.0410131551.1c43209e@posting.google.com>, james
><james_merch@hotmail.com> writes
>>Hi guys,
>>
>>I had an interview a few days ago and the interviewer
>>asked me this C++ question:
>>"Differentiate between a template class and class template?"
>>Can anyone explain me the differences?
>
>A template class is a template from which class definitions can be
>generated (just as a function template is a template from which
>functions can be generated.)

I'm pretty sure Francis meant "A class template" at the start of the
previous sentence ...  :)

>
>{Moderator's note: I'm pretty sure Francis meant the next sentence
>to begin with "A class template..." -mod/dk}

I'm pretty sure you're wrong Dietmar.  :)

>
>A template class is whatever you make it mean. Personally I do not use
>the term, but if I did it would be to refer to a class that had been
>generated from a template.

Yeah  - "template class" is context sensitive and no doubt it will
continue to be used a lot and nearly always means the same thing as
class template   e.g. google thread examples are "error in compiling
template class"  and "binary operator for template class" and "template
class nested types".  There's no doubting what is meant by these and
it's common usage  - which is why I think this is a "trick" question and
is checking for "clarity of thought" rather than "useful knowledge"  -
or perhaps it's checking for general familiarity with templates.

How many C++ programmers know what "explicit specialization" or "primary
template" are - a growing minority I suspect.

Graeme

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: richard@ex-parrot.com (Richard Smith)
Date: Wed, 20 Oct 2004 16:29:57 +0000 (UTC)
Raw View
Francis Glassborow wrote:
 >
 > A template class is whatever you make it mean. Personally I do not use
 > the term, but if I did it would be to refer to a class that had been
 > generated from a template.

I don't think it can mean whatever you want, as the term "template
class" appears in several places in the Standard.

In the sections on the Standard Library, many of the sections have
headings like "Template class vector" [23.2.4].

The term has also been used in 17.1.18 when a traits class is defined
as "a class that encapsulates a set of types and functions necessary
for template classes and template functions to manipulate objects of
types for which they are instantiated".  In this case taking template
class to mean a class which is an instantiation of a class template
seems reasonable.

In a number of other places the term is used synonymously with "class
template"; for instance, 26.2/1, "the header <complex> defines a
template class, and numberous functions ...".  The header *actually*
defines one class template, three explicit specialisations of that
class template.  24.5/1 is another such example.

Additionally, the term "non-template class" is used in several places
(14.5.3/6, 14.6.5/2, and twice in the hilarious 14.7.3/7); in these
contexts it seems to mean a class which is not an instantiation of a
class template, suggesting that "template class" should mean a class
which is an instantiation of a class template.

So it looks like "template class" is being used in different places in
the standard to mean a class that is an instantiation of a class
template, and a synonym for class template.

--
Richard Smith

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: james_merch@hotmail.com (james)
Date: Thu, 14 Oct 2004 22:02:39 +0000 (UTC)
Raw View
Hi guys,

I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?

Thanks, james


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: Thierry Miceli <nospam@nospam.com>
Date: Fri, 15 Oct 2004 16:10:41 +0000 (UTC)
Raw View
 > I had an interview a few days ago and the interviewer
 > asked me this C++ question:
 > "Differentiate between a template class and class template?"
 > Can anyone explain me the differences?

You'll find the answer here:

http://www.comeaucomputing.com/techtalk/templates/#terms

Regards,

Thierry
www.ideat-solutions.com

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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: suresh.lakshmanan@gmail.com (L.Suresh)
Date: Fri, 15 Oct 2004 16:10:41 +0000 (UTC)
Raw View
class template - Is actually a template that is a class.

Here Foo is a class template.

template <typename T>
class Foo {
};

template class - Is actually a class that is instantiated from a template.

Foo<int> f;

Here f has a type Foo<int>, which is a template class.

You can think think that the second word is qualified with first word.

"class template" : It is a template. template for what? template for class..
"template class" : It is a class. Is it ordinary class? It is a class
                    generated fro a template.

The same thing exists for funtcion template and template function.

HTH

--lsu

 > Hi guys,
 >
 > I had an interview a few days ago and the interviewer
 > asked me this C++ question:
 > "Differentiate between a template class and class template?"
 > Can anyone explain me the differences?
 >
 > Thanks, james
 >

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

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