Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++

>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous.

On 05/01/2011 12:54 AM, tymofey wrote:
>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way.
C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
class B1 { int i; float f; }; class B2 { int j; float f; }; class D : B1, B2 { int i, j; float f; void fn() { ... int v = super::i; // refers to B1::i int w = super::j; // refers to B2::j float x = super::f; // error: ambiguous float y = super<B1>::f; // refers to B1::f float z = super<B2>::f; // refers to B2::f ... } }; How ugly would the macros have to get to implement something like this with the current standards? - Marsh

On 01/05/2011 18:38, Marsh Ray wrote:
On 05/01/2011 12:54 AM, tymofey wrote:
>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way.
C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
class B1 { int i; float f; }; class B2 { int j; float f; };
class D : B1, B2 { int i, j; float f;
void fn() { ... int v = super::i; // refers to B1::i int w = super::j; // refers to B2::j float x = super::f; // error: ambiguous float y = super<B1>::f; // refers to B1::f float z = super<B2>::f; // refers to B2::f ... } };
How ugly would the macros have to get to implement something like this with the current standards?
You'd have to use SFINAE to tell whether B1::j exists and use B2::j otherwise. Should be doable.

It seems that just writing the name of the base class is far easier than doing macro stuff. ________________________________ Von: Mathias Gaunard <mathias.gaunard@ens-lyon.org> An: boost@lists.boost.org Gesendet: Sonntag, den 1. Mai 2011, 19:25:53 Uhr Betreff: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++ On 01/05/2011 18:38, Marsh Ray wrote:
On 05/01/2011 12:54 AM, tymofey wrote:
>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way.
C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
class B1 { int i; float f; }; class B2 { int j; float f; };
class D : B1, B2 { int i, j; float f;
void fn() { ... int v = super::i; // refers to B1::i int w = super::j; // refers to B2::j float x = super::f; // error: ambiguous float y = super<B1>::f; // refers to B1::f float z = super<B2>::f; // refers to B2::f ... } };
How ugly would the macros have to get to implement something like this with the current standards?
You'd have to use SFINAE to tell whether B1::j exists and use B2::j otherwise. Should be doable. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Pretty ugly :) ________________________________ Von: Marsh Ray <marsh@extendedsubset.com> An: boost@lists.boost.org Gesendet: Sonntag, den 1. Mai 2011, 18:38:09 Uhr Betreff: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++ On 05/01/2011 12:54 AM, tymofey wrote:
>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way.
C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
class B1 { int i; float f; }; class B2 { int j; float f; }; class D : B1, B2 { int i, j; float f; void fn() { ... int v = super::i; // refers to B1::i int w = super::j; // refers to B2::j float x = super::f; // error: ambiguous float y = super<B1>::f; // refers to B1::f float z = super<B2>::f; // refers to B2::f ... } }; How ugly would the macros have to get to implement something like this with the current standards? - Marsh _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Den 01-05-2011 07:54, tymofey skrev:
>>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
Please see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2881.html -Thorsten

Message du 02/05/11 22:50 De : "Thorsten Ottosen" A : boost@lists.boost.org Copie à : Objet : Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
Den 01-05-2011 07:54, tymofey skrev:
I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
Please see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2881.html
It will be great if this technique could be used to emulate single inheritance base class aliases, so instead of duplicating the base type template class bitset : private _Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
{ private: typedef _Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
_Base; // [...] }; we could just name it through a base typedef. template class bitset : public private_base<_Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
{ // private_base introduce base_type in scope here }; The single remaining problem is the forward constructor. We could add a macro that generates base like classes with specific names and have template class bitset : PRIVATE_BASE_ALIAS(_Base, (_Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
)) { // private_base introduce _Base type in scope here }; Of course macros are ugly and needs to double braquets. Best, Vicente

Den 02-05-2011 23:20, Vicente BOTET skrev:
Message du 02/05/11 22:50 De : "Thorsten Ottosen" A : boost@lists.boost.org Copie à : Objet : Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
Den 01-05-2011 07:54, tymofey skrev:
I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
Please see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2881.html
It will be great if this technique could be used to emulate single inheritance base class aliases, so instead of duplicating the base type
The single remaining problem is the forward constructor.
[snip]
We could add a macro that generates base like classes with specific names and have
template class bitset : PRIVATE_BASE_ALIAS(_Base, (_Base_bitset < ((_Nb)< 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
)) { // private_base introduce _Base type in scope here };
Of course macros are ugly and needs to double braquets.
Can you elaborate more on what you mean? If there is only one base class, we can just say using base::base; If there are more base classes, then we probably can use either of the inherited cobstructors. -Thorsten

Message du 03/05/11 00:00 De : "Thorsten Ottosen" A : boost@lists.boost.org Copie à : Objet : Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
Den 02-05-2011 23:20, Vicente BOTET skrev:
Message du 02/05/11 22:50 De : "Thorsten Ottosen" A : boost@lists.boost.org Copie à : Objet : Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
Den 01-05-2011 07:54, tymofey skrev:
I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous.
Please see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2881.html
It will be great if this technique could be used to emulate single inheritance base class aliases, so instead of duplicating the base type
The single remaining problem is the forward constructor.
[snip]
We could add a macro that generates base like classes with specific names and have
template class bitset : PRIVATE_BASE_ALIAS(_Base, (_Base_bitset < ((_Nb)< 1 ? 0 : ((_Nb) + numeric_limits::digits - 1) / numeric_limits::digits)
)) { // private_base introduce _Base type in scope here };
Of course macros are ugly and needs to double braquets.
Can you elaborate more on what you mean?
Sorry. I realized that we need yet another macro to declare the specific template class which make it much less attractive. If we have just a base class template private_base, protected_base and public_base seems to avoid the duplication. template class public_base : public T { public: typedef public_base base_type; using T::T; }; -- Vicente

What about: template < size_t _Nb, base = _Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits<unsigned long>::digits - 1) / numeric_limits<unsigned long>::digits) >
class bitset : base { bitset(size_t n) : base(n) { } }; Something like this compiles for me on G++4.6.0. It has the disadvantage of changing the number and type of template parameters, but we accept that for things like enable_if. This has the advantage that the identifier 'base' is not inherited accidentally into class scopes where it is no longer correct. Which is something that always makes me uncomfortable with the "typedef ... this_type" technique. - Marsh

From: Marsh Ray What about:
template < size_t _Nb, base = _Base_bitset < ((_Nb) < 1 ? 0 : ((_Nb) + numeric_limits<unsigned long>::digits - 1) / numeric_limits<unsigned long>::digits) >
class bitset : base { bitset(size_t n) : base(n) { } };
I assume you mean "typename base = _Base_bitset"? The trick is nice, but another disadvantage is that it won't work with CRTP. Best regards, RK

Den 03-05-2011 15:07, Sebastian Redl skrev:
On 02.05.2011 23:58, Thorsten Ottosen wrote:
If there is only one base class, we can just say
using base::base;
That's a C++0x constructor inheriting directive.
genau ... our paper was not even discussed for C++0x. -Thorsten

I think I'll wait for the C++0x standard to be released :) ________________________________ Von: Thorsten Ottosen <thorsten.ottosen@dezide.com> An: boost@lists.boost.org Gesendet: Dienstag, den 3. Mai 2011, 17:03:48 Uhr Betreff: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++ Den 03-05-2011 15:07, Sebastian Redl skrev:
On 02.05.2011 23:58, Thorsten Ottosen wrote:
If there is only one base class, we can just say
using base::base;
That's a C++0x constructor inheriting directive.
genau ... our paper was not even discussed for C++0x. -Thorsten _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Thats true. I see your point. Well even if one would allow only single inheritance in C++ this would probably break old code. ________________________________ Von: tymofey <tymofey@qip.ru> An: boost@lists.boost.org Gesendet: Sonntag, den 1. Mai 2011, 7:54:18 Uhr Betreff: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++ >>I was wondering if it makes sense to add the well known super or base keyword to the C++ language in a generic way. C++ has multiple inheritance, while java and C# do not, so super would be ambigous. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (8)
-
Marsh Ray
-
Mathias Gaunard
-
Max Hölzer
-
Robert Kawulak
-
Sebastian Redl
-
Thorsten Ottosen
-
tymofey
-
Vicente BOTET