🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Tim Boemker Wed, 06 Mar 1996 18:13
possible extension -- typeof(expr)
#3604
Author: Tim Boemker
Date: Wed, 06 Mar 1996 18:13
23 lines
1351 bytes
Many times in working with STL I've wished for a new operator to return
the type of an expression, much the same way sizeof returns the size of
an expression.

It would allow programs like the following, for example:

   set<foo, less<foo> > s;
   for(typeof(s)::iterator i = s.begin(); i != s.end(); i++)
      // do something

I suppose this must have been considered by now.  Has anything come of
it?

Tim Boemker
Optimum Group


[ 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
]
Re: possible extension -- typeof(expr)
#3618
Author: Jason Merrill
Date: Wed, 06 Mar 1996 21:45
30 lines
1824 bytes
>>>>> Tim Boemker <tjb839@zacatecas.optimum.com> writes:

> Many times in working with STL I've wished for a new operator to return
> the type of an expression, much the same way sizeof returns the size of
> an expression.

> It would allow programs like the following, for example:

>    set<foo, less<foo> > s;
>    for(typeof(s)::iterator i = s.begin(); i != s.end(); i++)
>       // do something

> I suppose this must have been considered by now.  Has anything come of
> it?

It has come up in the committee, but no-one has made a formal proposal, and
it's too late now.

g++ has had typeof for a very long time; I believe some other compilers
(Metaware?) have similar functionality with a different name.

Jason


[ 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
]
Re: possible extension -- typeof(expr)
#3621
Author: Pablo Halpern
Date: Fri, 08 Mar 1996 16:23
37 lines
2163 bytes
tjb839@zacatecas.optimum.com (Tim Boemker) wrote:

>Many times in working with STL I've wished for a new operator to return
>the type of an expression, much the same way sizeof returns the size of
>an expression.
>
>It would allow programs like the following, for example:
>
>   set<foo, less<foo> > s;
>   for(typeof(s)::iterator i = s.begin(); i != s.end(); i++)
>      // do something

Actually, I'm surprized that the notation s.iterator is not valid. If
iterator were a static variable or function, instead of a nested class
or typedef, then it WOULD be valid. Has there been any discusion of
permitting this syntax? It seems like it would be easy to implement
(just an extention of the current scope-resolution rules) and would
solve many of the problems that typeof() addresses. The example would
look like this:

   set<foo, less<foo> > s;
   for(s.iterator i = s.begin(); i != s.end(); i++)
   //  ^^^^^^^^^^ why isn't this currently valid?
      // do something

-------------------------------------------------------------
Pablo Halpern                   phalpern@truffle.ultranet.com

I am self-employed. Therefore, my opinions *do* represent 
those of my employer.
---
[ 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: possible extension -- typeof(expr)
#3626
Author: Raja R Harinath
Date: Sat, 09 Mar 1996 00:06
47 lines
2505 bytes
In article <u9ag1t3njg.fsf@yorick.cygnus.com> 
jason@cygnus.com (Jason Merrill) writes:
> 
> >>>>> Tim Boemker <tjb839@zacatecas.optimum.com> writes:
> 
> > Many times in working with STL I've wished for a new operator to return
> > the type of an expression, much the same way sizeof returns the size of
> > an expression.
> 
> > It would allow programs like the following, for example:
> 
> >    set<foo, less<foo> > s;
> >    for(typeof(s)::iterator i = s.begin(); i != s.end(); i++)
> >       // do something
> 
> > I suppose this must have been considered by now.  Has anything come of
> > it?
> 
> It has come up in the committee, but no-one has made a formal proposal, and
> it's too late now.

Instead of introducing a new keyword `typeof', what about allowing this
usage:

  set <foo, less<foo> > s;
  for (typename s.iterator i = s.begin(); ... )
       ^^^^^^^^ ^^^
       |        |
      (1)      (2)

1. Extending `typename' to a non-template context to allow (2).

2. Accessing a member type/typedef using the `.' syntax (and against an
   object) instead of the `::' syntax against a typename.

(1) above solves the parsing problem associated with allowing syntax (2)
independently, and uses an existing keyword (and extends its meaning,
without, IMO, overloading it).

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