🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Steve Willer Fri, 08 Mar 1996 02:10
typename?
#3616
Author: Steve Willer
Date: Fri, 08 Mar 1996 02:10
12 lines
1142 bytes
I saw in the brochure for Borland C++ 5.0 that it will include support for
numerous new C++ features, including the "typename" keyword. Could anyone
enlighten me as to what that is? I couldn't find it in the April WP.

This isn't equivalent to the "typeof" keyword that I want so much, is it?
---
[ 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.
]
Re: typename?
#3614
Author: Matt Austern
Date: Fri, 08 Mar 1996 03:23
50 lines
2770 bytes
In article <m0tupLs-000CajC@sqarc.sq.com> willer@carolian.com (Steve Willer)
writes:

> I saw in the brochure for Borland C++ 5.0 that it will include support for
> numerous new C++ features, including the "typename" keyword. Could anyone
> enlighten me as to what that is? I couldn't find it in the April WP.
> 
> This isn't equivalent to the "typeof" keyword that I want so much, is it?

No.  The typename keyword is a consequence of the new rules for name
resolution in templates.  Brief summary: there's a new disambiguation
rule saying that a name used in a template is assumed not to be a type
unless it has been explicitly declared to be a type.  

Disambiguation rules like this are good, since they make it possible
to check template syntax even before the template has been
instantiated.  This one, though, presents a problem.  Suppose you want
to write code like this.
    template<class Container>
    void f(Container X)
    {
       Container::value_type tmp = *(X.begin());
       // do something with tmp.
    }
This is a syntax error, since Container::value_type is assumed not to
be the name of a type.  (And I hope everyone agrees that this isn't a
contrived example.  The STL source is full of examples like this.)

The typename keyword was introduced to solve this problem; it says
that the name following it refers to a type.  The correct way to write
this code snippet, then, is as follows.
    template<class Container>
    void f(Container X)
    {
       typename Container::value_type tmp = *(X.begin());
       // do something with tmp.
    }

This is described in section 14.2 [temp.res] of the WP.
-- 
Matt Austern
SGI: MTI Compilers Group
austern@isolde.mti.sgi.com
---
[ 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.
]
Re: typename?
#3627
Author: David Sachs
Date: Sat, 09 Mar 1996 04:34
29 lines
2036 bytes
willer@carolian.com (Steve Willer) writes:

>I saw in the brochure for Borland C++ 5.0 that it will include support for
>numerous new C++ features, including the "typename" keyword. Could anyone
>enlighten me as to what that is? I couldn't find it in the April WP.

>This isn't equivalent to the "typeof" keyword that I want so much, is it?

The typename keyword can be found in the draft standard. It is used
in template declarations to indicate that the following item is a
type. It is used in several places in the library definitions in a
construct like the following:

// class T is assumed to define a type xx
template <class T> class U
{
  typedef typename T::xx xx; // Makes xx same as type xx in class T
  ...
}
-- 
***** Listen Americans, the IRS is your taxer,  the IRS is one. *****
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942      Deparment Fax: 1 708 840 3785
---
[ 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                             ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads