That's a great feature. I don't see many languages investing enough focus into this kind of "delegation wiring."
That's a great feature. I don't see many languages investing enough focus into this kind of "delegation wiring."
struct A { int a; alias a this; } struct B { A a; alias a this; } struct C { B b; alias b this; }
static assert(C(42) == 42);
Combined with D's support for compile-time protocols, this allows for some very expressive, powerful and lighting fast code.
http://golang.org/doc/effective_go.html#embedding
http://golang.org/ref/spec#Struct_types
Note that there's also interface embedding which is a different thing.
Yes, it's a different feature, but is not multiple inheritance either (although I understand why, at a first glance, you'd think it would seems like that). It's just composition. In this new example, look how you can do b.myInt, even though b is now a bar, not a foo. In fact this happened in the old example too, but it was invisible. This is how the Lock function accessed the mutex.