From 721dd55da74a01dbd842e6b48e4845c2b501164a Mon Sep 17 00:00:00 2001 From: MetaLang Date: Sat, 11 Apr 2015 02:08:43 -0300 Subject: [PATCH] Improve Blackhole documentation --- std/typecons.d | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index d7a490d527d..de9abeb7206 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -2565,33 +2565,37 @@ The name came from $(WEB search.cpan.org/~sburke/Class-_BlackHole-0.04/lib/Class/_BlackHole.pm, Class::_BlackHole) Perl module by Sean M. Burke. -Example: --------------------- -abstract class C -{ - int m_value; - this(int v) { m_value = v; } - int value() @property { return m_value; } +Params: + Base = A non-final class for `BlackHole` to inherit from. - abstract real realValue() @property; - abstract void doSomething(); -} +See_Also: + $(LREF AutoImplement), $(LREF generateEmptyFunction) + */ +alias BlackHole(Base) = AutoImplement!(Base, generateEmptyFunction, isAbstractFunction); -void main() +/// +unittest { + import std.math: isNaN; + + static abstract class C + { + int m_value; + this(int v) { m_value = v; } + int value() @property { return m_value; } + + abstract real realValue() @property; + abstract void doSomething(); + } + auto c = new BlackHole!C(42); - writeln(c.value); // prints "42" + assert(c.value == 42); - // Abstract functions are implemented as do-nothing: - writeln(c.realValue); // prints "NaN" - c.doSomething(); // does nothing + // Returns real.init which is NaN + assert(c.realValue.isNaN); + // Abstract functions are implemented as do-nothing + c.doSomething(); } --------------------- - -See_Also: - AutoImplement, generateEmptyFunction - */ -alias BlackHole(Base) = AutoImplement!(Base, generateEmptyFunction, isAbstractFunction); unittest {