Skip to content

Commit

Permalink
Merge pull request #3175 from MetaLang/blackhole-doc
Browse files Browse the repository at this point in the history
Improve Blackhole documentation
  • Loading branch information
JakobOvrum committed Apr 11, 2015
2 parents 695a98f + 721dd55 commit 1f6c706
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions std/typecons.d
Expand Up @@ -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
{
Expand Down

0 comments on commit 1f6c706

Please sign in to comment.