Topic: Suggestion: parent
Author: dsp@bdal.de (=?ISO-8859-1?Q?=22Daniel_Kr=FCgler_=28ne_Spangenberg=29=22?=)
Date: Wed, 11 May 2005 01:34:39 GMT Raw View
Hello James Dennett,
James Dennett schrieb:
> This has been discussed a number of times here:
> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/b=
cdfb80dbd695f38/cc4cde7f50c0fd8b?q=3Dcomp.std.C%2B%2B+parent&rnum=3D4#cc4=
cde7f50c0fd8b=20
>
> or
> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/7=
45b8fd5e5fadce3/61758e00b849500f?q=3Dcomp.std.C%2B%2B+parent&rnum=3D6#617=
58e00b849500f=20
>
> would be examples. Names suggested include "super" and "inherited".
> In the past the idea hasn't had all that much support, given that
> it's not hard to add a typedef manually and that generalizations to
> multiple inheritance are either restricted or complicated.=20
You are right, but to my opinion it would be quite useful to have an=20
extended typedef mechanism which allows to
define a typedef at the point of derivation (This has already been=20
proposed by others), e.g.
class B1 {...};
class B2 {...};
class Derived : public typedef B1 Base1, protected typedef B2 Base2 {
=2E
};
or
class Derived : public Base1 =3D B1, protected Base2 =3D B2 {
=2E
};
This extension has the advantage that complicated, template-based=20
inheritance relations can be expressed in a
consistent way.
Greetings from Bremen,
Daniel Kr=FCgler
---
[ 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: musiphil@bawi.org (Seungbeom Kim)
Date: Wed, 11 May 2005 06:02:33 GMT Raw View
Daniel Kr=FCgler (ne Spangenberg) wrote:
> Hello James Dennett,
>=20
> James Dennett schrieb:
>=20
>> This has been discussed a number of times here:
>> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/=
bcdfb80dbd695f38/cc4cde7f50c0fd8b?q=3Dcomp.std.C%2B%2B+parent&rnum=3D4#cc=
4cde7f50c0fd8b=20
>>
>> or
>> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/=
745b8fd5e5fadce3/61758e00b849500f?q=3Dcomp.std.C%2B%2B+parent&rnum=3D6#61=
758e00b849500f=20
>>
>> would be examples. Names suggested include "super" and "inherited".
>> In the past the idea hasn't had all that much support, given that
>> it's not hard to add a typedef manually and that generalizations to
>> multiple inheritance are either restricted or complicated.=20
>=20
>=20
> You are right, but to my opinion it would be quite useful to have an=20
> extended typedef mechanism which allows to
> define a typedef at the point of derivation (This has already been=20
> proposed by others), e.g.
>=20
> class B1 {...};
> class B2 {...};
>=20
> class Derived : public typedef B1 Base1, protected typedef B2 Base2 {
> .
> };
>=20
> or
>=20
> class Derived : public Base1 =3D B1, protected Base2 =3D B2 {
> .
> };
>=20
> This extension has the advantage that complicated, template-based=20
> inheritance relations can be expressed in a
> consistent way.
That has already been mentioned, too: see
http://groups-beta.google.com/group/comp.std.c++/browse_frm/thread/21f10b=
a31b699661/363cc91f87e78bb0#363cc91f87e78bb0
http://groups-beta.google.com/group/comp.std.c++/browse_frm/thread/21f10b=
a31b699661/12eeaba4410ade3e#12eeaba4410ade3e
I like the second one better, because it's more clear and more succinct.
--=20
Seungbeom Kim
---
[ 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: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 11 May 2005 20:59:03 GMT Raw View
James Dennett wrote:
> In the past the idea hasn't had all that much support, given that
> it's not hard to add a typedef manually and that generalizations to
> multiple inheritance are either restricted or complicated.
It's the MI case where this is most useful, but complicated template
base classes could use the help as well. I don't see anything all that
difficult - simply let inherited<N> be the (N+1)th direct base class,
and let inherited::name be the name found by lookup as if name were not
defined in the derived class.
---
[ 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: house@usq.edu.au (Ron House)
Date: Wed, 11 May 2005 20:58:41 GMT Raw View
James Dennett wrote:
> Ron House wrote:
>
>> I don't know if this has been suggested, but a neat way to refer to
>> the parent of a class would be very useful. Thus, if C inherits from
>> B, "parent" used inside C, would be B. This would be handy with
>> template arguments, and when classes include code from macros or
>> templates that want to mention the ancestor. I ran into the problem
>> when designing a system to automatically generate a collection of
>> classes for writing html from special short descriptions of html
>> elements. My canned code got inserted into various classes and I
>> needed to call ancestor methods. I found I had to keep track of the
>> ancestor class names with complicated macros.
>>
>
> This has been discussed a number of times here:
> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/bcdfb80dbd695f38/cc4cde7f50c0fd8b?q=comp.std.C%2B%2B+parent&rnum=4#cc4cde7f50c0fd8b
>
> or
> http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/745b8fd5e5fadce3/61758e00b849500f?q=comp.std.C%2B%2B+parent&rnum=6#61758e00b849500f
>
> would be examples. Names suggested include "super" and "inherited".
> In the past the idea hasn't had all that much support, given that
> it's not hard to add a typedef manually and that generalizations to
> multiple inheritance are either restricted or complicated.
Yes, multiple inheritance is the problem area, of course. But I think
the utility of it in automatically-generated code is being
underestimated if it was suggested that the problem is always easy to
fix with a typedef or two. Perhaps it is easily disposed of by treating
it like ambiguous function calls - if there is no ambiguity, it gives
you the parent, otherwise you can't use it.
--
Ron House house@usq.edu.au
http://www.sci.usq.edu.au/staff/house
---
[ 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: kon@iki.fi (Kalle Olavi Niemitalo)
Date: Thu, 12 May 2005 06:06:53 GMT Raw View
hyrosen@mail.com (Hyman Rosen) writes:
> It's the MI case where this is most useful, but complicated template
> base classes could use the help as well. I don't see anything all that
> difficult - simply let inherited<N> be the (N+1)th direct base class,
> and let inherited::name be the name found by lookup as if name were not
> defined in the derived class.
How would you use inherited<N> in practice? I presume you
wouldn't write e.g. inherited<2> directly, but would instead get
the N from somewhere else: inherited<refcount_base_index>.
However, I expect it would be easier and more maintainable to
just use a typedef in that case.
Or were you going to loop over all direct base classes at compile
time? Then you'd also need to know how many there are... it may
be possible to find that out with some ugly templates and SFINAE,
but I'd hate to have a new feature whose use requires that.
---
[ 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: house@usq.edu.au (Ron House)
Date: Mon, 16 May 2005 16:18:53 GMT Raw View
Hyman Rosen wrote:
> James Dennett wrote:
>
>> In the past the idea hasn't had all that much support, given that
>> it's not hard to add a typedef manually and that generalizations to
>> multiple inheritance are either restricted or complicated.
>
>
> It's the MI case where this is most useful, but complicated template
> base classes could use the help as well. I don't see anything all that
> difficult - simply let inherited<N> be the (N+1)th direct base class,
> and let inherited::name be the name found by lookup as if name were not
> defined in the derived class.
Now that's really good! A very nice example of lateral thinking. As I
understand it, you are saying: We can't uniquely identify the parent,
but we can pretend we didn't define this name here and see what
definitions we get from elsewhere.
The same idea would work for ordinary enclosed blocks, suggesting that
perhaps "inherited" isn't quite the right name. Or perhaps they aren't
quite the same thing: in an enclosed class, we might want an inherited
definition or an enclosing definition (ignoring all inherited versions).
So maybe this implies we need inherited::name and maybe outside::name?
Not that I want to add complexity: I suspect the inherited one is much
more useful than the outside one, but I am willing to be told that my
imagination isn't working well enough!
As for inherited<N>, I think a more useful way to define it would be:
ask all ancestors for all inherited<N-1> definitions of name.
--
Ron House house@usq.edu.au
http://www.sci.usq.edu.au/staff/house
---
[ 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: hyrosen@mail.com (Hyman Rosen)
Date: Mon, 16 May 2005 16:19:33 GMT Raw View
Kalle Olavi Niemitalo wrote:
> How would you use inherited<N> in practice? I presume you
> wouldn't write e.g. inherited<2> directly
Yes, you would write it directly. It's for when a base class is
a complicated template expression and you have to refer to it
again, such as calling it's constructors.
---
[ 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: hyrosen@mail.com (Hyman Rosen)
Date: Mon, 16 May 2005 16:18:34 GMT Raw View
Ron House wrote:
> Perhaps it is easily disposed of by treating it like ambiguous function calls -
> if there is no ambiguity, it gives you the parent, otherwise you can't use it.
The way it should work is that "inherited::name" means lookup "name" as if this
class did not define it. If there are multiple base classes, all of them are
searched. If the result is ambiguous (after applying the overloading rules if
it's a function) or missing, then you get a compilation error.
---
[ 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: house@usq.edu.au (Ron House)
Date: Tue, 10 May 2005 04:36:44 GMT Raw View
I don't know if this has been suggested, but a neat way to refer to the
parent of a class would be very useful. Thus, if C inherits from B,
"parent" used inside C, would be B. This would be handy with template
arguments, and when classes include code from macros or templates that
want to mention the ancestor. I ran into the problem when designing a
system to automatically generate a collection of classes for writing
html from special short descriptions of html elements. My canned code
got inserted into various classes and I needed to call ancestor methods.
I found I had to keep track of the ancestor class names with complicated
macros.
--
Ron House house@usq.edu.au
http://www.sci.usq.edu.au/staff/house
---
[ 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: jdennett@acm.org (James Dennett)
Date: Tue, 10 May 2005 05:51:17 GMT Raw View
Ron House wrote:
> I don't know if this has been suggested, but a neat way to refer to the
> parent of a class would be very useful. Thus, if C inherits from B,
> "parent" used inside C, would be B. This would be handy with template
> arguments, and when classes include code from macros or templates that
> want to mention the ancestor. I ran into the problem when designing a
> system to automatically generate a collection of classes for writing
> html from special short descriptions of html elements. My canned code
> got inserted into various classes and I needed to call ancestor methods.
> I found I had to keep track of the ancestor class names with complicated
> macros.
>
This has been discussed a number of times here:
http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/bcdfb80dbd695f38/cc4cde7f50c0fd8b?q=comp.std.C%2B%2B+parent&rnum=4#cc4cde7f50c0fd8b
or
http://groups-beta.google.com/group/comp.std.c++/browse_thread/thread/745b8fd5e5fadce3/61758e00b849500f?q=comp.std.C%2B%2B+parent&rnum=6#61758e00b849500f
would be examples. Names suggested include "super" and "inherited".
In the past the idea hasn't had all that much support, given that
it's not hard to add a typedef manually and that generalizations to
multiple inheritance are either restricted or complicated.
-- James
---
[ 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 ]