class template conflict
Basile B.
b2.temp at gmx.com
Sun Dec 23 14:31:36 UTC 2018
On Sunday, 23 December 2018 at 12:09:31 UTC, Michelle Long wrote:
> class X
> {
>
> }
>
> class X(int N) : X
> {
>
> }
>
> Is there any real reason we can't do this?
>
> It is very nice to be able to treat X like the base and X!n as
> a derived class.
>
> Sure we can do
>
> class X(int N) : X!0
> {
> static if(N == 0)
> {
> }
> }
>
> but this is very ugly, in my code I always have to use X!0 as
> the basis!
>
> I do not think there is any harm to allow this since the
> templated class always has to specify N. It is not like we can
> do
>
> class X(int N = 0) : X
> {
> static if(N == 0)
> {
> }
> }
>
>
> Actually we can, so... I don't see the point in not allowing
> the first case, they are logically equivalent. That static if
> is just ugly and it is defining the base class inside the
> derived class which seems unnatural.
You have this option too:
```
template X(N...)
if (N.length == 0 ||
N.length == 1 && is(typeof(N[0]) == int))
{
static if (N.length == 0)
class X {}
else class X : X!() {}
}
auto base = new X!();
auto derived = new X!8;
```
More simple is : do not use the same identifier ;)
More information about the Digitalmars-d-learn
mailing list