November 25, 2009
bearophile wrote:
> Don:
>> That's been requested many times. I posted a patch to Walter to do exactly that. It was beautiful. It detected recursive template expansions, and gave really nice error messages. Silently rejected.
>> Sigh.
> 
> If your patch is well done, works with LDC too, I see no reason to refuse this feature even for D1, it doesn't change the language and just makes debugging simpler. So let's not surrender yet. How much time ago Walter has refused this patch? Lately Walter is more receptive for your patches. I can create a new thread about this in the main D NG. If 8+ persons say they want this patch, and it works correctly, then Walter can change his mind.

Please don't do that just yet. It's something that can wait until the D2 stuff is finished. It can be added at any time. Some of the other things are urgent.

November 25, 2009
Don:
> Please don't do that just yet. It's something that can wait until the D2 stuff is finished. It can be added at any time. Some of the other things are urgent.

OK :-) You are right, as usual.

Bye,
bearophile
November 25, 2009
Saaa a écrit :
> struct S : Pos {}
> Why is this not possible? 
> 

It's not and structures have no vtable... fortunately.

But, could it be a good idea to use the "inheritance operator" to do some kind of static inheritance like we do with mixins or to force implementation at compile-time ?


1. inheriting from an interfaces would force function implementation at compile time:

interface IFoo
{
	void foo();
}

// Would not compile
// "Struct S static interface function IFoo.foo isn't implemented"
struct S : IFoo {}

// Would compile
struct S : IFoo { void foo() {} }


2. inheriting from a structure would do some kind a mixin.

struct S1 { void foo(); static void bar(); }
struct S2 : S1 {}
S1.bar();
S1 a; a.foo(); a.bar();


3. class and structs could share interfaces for compile time function name resolution. I think this already work using untyped template arguments.

interface IFoo
{
	void foo();
}

class C : IFoo // dynamic inheritance
{
	void foo()
	{
	}
}

struct S : IFoo // static inheritance
{
	void foo()
	{
	}
}

class Bar(IFoo FOO)
{
	void bar(FOO thing)
	{
		thing.foo();
	}
}


4. casting could be forbidden OR :

struct A { int a; }
struct B : A {} // B implements "int a" as in 2

A a; B b = a; // would do something like b.a = a.a
B b; A a = b; // would do something like a.a = b.a


--
AF
1 2 3
Next ›   Last »