Topic: Q on "instance member typedefs" /PLEAS POST!
Author: "maxim" <maxk@touro.edu>
Date: 1999/10/30 Raw View
I have recently been thinking of exactly your example
std::vector<std::string> v;
for(v.iterator i=v.begin(); i!=v.end(); ++i) {...}
// Illegal, need std::vector<std::string>::iterator
and I thought that this usage would be great. (though I didn't think of your
implementation). I think this functionality could open great opportunities
for the language, so anyone who agrees with me (or offers a good reason to
the contrary), PLEASE POST, I am sure someone on this newsgroup is either on
the commity or knows someone who is!
max.
John Panzer wrote in message <38148EE5.E7BDA7F6@netscape.com>...
>In C++, we can have member typedefs:
>
>struct A {typedef int Foo;}
>
>and we can refer to them using scope resolution syntax:
>
>A::Foo foo;
>
>but we cannot use the member "." notation:
>
>A a;
>a.Foo foo; // Illegal
>
>All information needed for this declaration is available to the compiler
>at
>compile time. Why is it disallowed?
>
>If we had this, we could do (for example) the following:
>
> template <class T> struct type_trait {typedef T Type;}
> template <class T> type_trait<T> same_type(T const &) {
> return type_trait<T>();
> }
> ...
> int i;
> same_type(i).Type j; // Declare j as "same type as" i
>
>As far as I know, there is currently no portable way to do this.
>
>Having this could also simplify STL usage:
>
> std::vector<std::string> v;
> for(v.iterator i=v.begin(); i!=v.end(); ++i) {...}
> // Illegal, need std::vector<std::string>::iterator
>
>And I'm guessing that it could simplify some template implementations.
>Was
>this ever discussed during standardization? And if so, does anyone
>happen
>to know the reasons for rejecting it?
>
>Thanks,
>John Panzer
>---
>[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]