Skip to content

Commit

Permalink
Fix Issue 16135 - missing std.format import in std.algorithm.comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Dec 30, 2016
1 parent 3c0b47a commit d1b59d3
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 d1b59d3

Please sign in to comment.