Topic: Q on "instance member typedefs
Author: John Panzer <jpanzer@netscape.com>
Date: 1999/11/03 Raw View
Darin Adler wrote:
> Hyman Rosen wrote:
>
> >> [...] There would be the question of whether the
> >> expression left of the '.' would be evaluated, but that's similar
> >> to the case when the name on the right is a static member. And of
> >> course we're talking about the static type of the expression.
>
> John Panzer <jpanzer@acm.org> wrote:
>
> > I think that's a solved problem; I imagine it would follow the
> > same rules that "sizeof" does:
> >
> > sizeof(malloc(0)); // ==sizeof(void*)
>
> It's not clear whether this should follow the rules that sizeof does or (as
> Hyman Rosen suggests) the rules for a call to a static member function with
> an expression to the left of the '.'.
>
> The standard specifically says that in the case of a call to a static member
> function, the expression to the left of the '.' is evaluated even though the
> result is unnecessary (5.2.5/1, check the footnote).
OK; either way, it's a solved problem. (For the actual application, compilers
would probably be able to optimize away the inline "{return T();}" body, so
I don't really care which way it would be specified.) Seems like there are
no showstoppers here.
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 ]
Author: Darin Adler <darin@bentspoon.com>
Date: 1999/11/02 Raw View
Hyman Rosen wrote:
>> [...] There would be the question of whether the
>> expression left of the '.' would be evaluated, but that's similar
>> to the case when the name on the right is a static member. And of
>> course we're talking about the static type of the expression.
John Panzer <jpanzer@acm.org> wrote:
> I think that's a solved problem; I imagine it would follow the
> same rules that "sizeof" does:
>
> sizeof(malloc(0)); // ==sizeof(void*)
It's not clear whether this should follow the rules that sizeof does or (as
Hyman Rosen suggests) the rules for a call to a static member function with
an expression to the left of the '.'.
The standard specifically says that in the case of a call to a static member
function, the expression to the left of the '.' is evaluated even though the
result is unnecessary (5.2.5/1, check the footnote).
-- Darin
---
[ 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 ]
Author: John Panzer <jpanzer@acm.org>
Date: 1999/10/31 Raw View
Hyman Rosen wrote:
> John Panzer <jpanzer@netscape.com> writes:
> > 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?
>
> No really good reason. There would be the question of whether the
> expression left of the '.' would be evaluated, but that's similar
> to the case when the name on the right is a static member. And of
> course we're talking about the static type of the expression.
I think that's a solved problem; I imagine it would follow the
same rules that "sizeof" does:
sizeof(malloc(0)); // ==sizeof(void*)
> This topic often comes up as the 'typeof' proposal.
Referring to the g++ keyword? Note that this is slightly
different -- no new keyword needed, just removal of a
restriction on the use of nested class typedefs.
I didn't find much useful using "typeof" in a deja search.
Thanks,
John
---
[ 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 ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/10/30 Raw View
John Panzer wrote:
>
> 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
A better choice would be:
A a;
a::Foo foo; // Illegal, too.
This would make it clear that the expression is not evaluated
(which is not necessary since the static type is known at
compile time), and thus code like
A* p = NULL;
(*p)::Foo foo; // Would remain illegal if *p were evaluated
would be allowed.
Using the dot notation without evaluating the lhs of it would
be confusing.
[...]
---
[ 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 ]
Author: Hyman Rosen <hymie@prolifics.com>
Date: 1999/10/28 Raw View
John Panzer <jpanzer@netscape.com> writes:
> 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?
No really good reason. There would be the question of whether the
expression left of the '.' would be evaluated, but that's similar
to the case when the name on the right is a static member. And of
course we're talking about the static type of the expression.
This topic often comes up as the 'typeof' proposal.
---
[ 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 ]
Author: John Panzer <jpanzer@netscape.com>
Date: 1999/10/27 Raw View
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 ]