Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1793 from schveiguy/addbooldur
Browse files Browse the repository at this point in the history
Fix issue 8411 - add opCast!bool support for Duration.
  • Loading branch information
schveiguy authored Mar 17, 2017
2 parents f6ab1e2 + 33b41c1 commit 827fb5d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/time.d
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,22 @@ public:
}
}

/++
Allow Duration to be used as a boolean.
Returns: `true` if this duration is non-zero.
+/
bool opCast(T : bool)() const nothrow @nogc
{
return _hnsecs != 0;
}

unittest
{
auto d = 10.minutes;
assert(d);
assert(!(d - d));
assert(d + d);
}

//Temporary hack until bug http://d.puremagic.com/issues/show_bug.cgi?id=5747 is fixed.
Duration opCast(T)() const nothrow @nogc
Expand Down

0 comments on commit 827fb5d

Please sign in to comment.