Skip to content

Commit

Permalink
Merge pull request #5006 from wilzbach/fix-16135
Browse files Browse the repository at this point in the history
Fix Issue 16135 - missing std.format import in std.algorithm.comparison
  • Loading branch information
JackStouffer committed Jan 3, 2017
2 parents 3c0b47a + d1b59d3 commit 7904edd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions std/algorithm/comparison.d
Expand Up @@ -237,6 +237,7 @@ Note: $(D castSwitch) can only be used with object types.
auto castSwitch(choices...)(Object switchObject)
{
import core.exception : SwitchError;
import std.format : format;

// Check to see if all handlers return void.
enum areAllHandlersVoidResult = {
Expand Down Expand Up @@ -494,6 +495,23 @@ auto castSwitch(choices...)(Object switchObject)
)());
}

@system unittest
{
interface I { }
class B : I { }
class C : I { }

assert((new B()).castSwitch!(
(B b) => "class B",
(I i) => "derived from I",
) == "class B");

assert((new C()).castSwitch!(
(B b) => "class B",
(I i) => "derived from I",
) == "derived from I");
}

/** Clamps a value into the given bounds.
This functions is equivalent to $(D max(lower, min(upper,val))).
Expand Down

0 comments on commit 7904edd

Please sign in to comment.