-
-
Notifications
You must be signed in to change notification settings - Fork 33
dlib.core.oop
Timur Gafarov edited this page Apr 26, 2017
·
2 revisions
Prototype-based OOP system for structs. Uses some template black magic to implement:
- Multiple inheritance
- Parametric polymorphism (struct interfaces)
- Interface inheritance.
Inserts structs specified by PT
type tuple as members and a dispatcher method that statically transfers any method calls and member accesses to corresponding child struct.
-
bool implements(T, I)()
- returnstrue
if structT
has the same members and methods as structI
. This allows to use structs as static interfaces in generic code.
struct Foo
{
int x = 100;
int foo() { return 11; }
}
struct Bar
{
int y = 99;
int bar() { return 22; }
}
struct FooBar
{
mixin Inherit!(Foo, Bar);
}
FooBar fb;
fb.x *= 2;
fb.y = 10;
assert(fb.x == 200);
assert(fb.y == 10);
assert(fb.foo() == 11);
assert(fb.bar() == 22);