Boost logo

Boost :

Subject: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-02 17:20:03


> Message du 02/05/11 22:50
> De : "Thorsten Ottosen"
> A : boost_at_[hidden]
> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk