BlackHole

BlackHole!Base is a subclass of Base which automatically implements all abstract member functions in Base as do-nothing functions. Each auto-implemented function just returns the default value of the return type without doing anything.

The name came from Class::_BlackHole Perl module by Sean M. Burke.

alias BlackHole(Base) = AutoImplement!(Base, generateEmptyFunction, isAbstractFunction)

Parameters

Base

A non-final class for BlackHole to inherit from.

Examples

1 import std.math : isNaN;
2 
3 static abstract class C
4 {
5     int m_value;
6     this(int v) { m_value = v; }
7     int value() @property { return m_value; }
8 
9     abstract real realValue() @property;
10     abstract void doSomething();
11 }
12 
13 auto c = new BlackHole!C(42);
14 assert(c.value == 42);
15 
16 // Returns real.init which is NaN
17 assert(c.realValue.isNaN);
18 // Abstract functions are implemented as do-nothing
19 c.doSomething();

See Also

Meta

Suggestion Box / Bug Report