Fix Issue 16135 - missing std.format import in std.algorithm.comparison

This commit is contained in:
Sebastian Wilzbach 2016-12-30 08:59:25 +01:00
parent 3c0b47ab51
commit d1b59d3f2e

View file

@ -237,6 +237,7 @@ Note: $(D castSwitch) can only be used with object types.
auto castSwitch(choices...)(Object switchObject) auto castSwitch(choices...)(Object switchObject)
{ {
import core.exception : SwitchError; import core.exception : SwitchError;
import std.format : format;
// Check to see if all handlers return void. // Check to see if all handlers return void.
enum areAllHandlersVoidResult = { enum areAllHandlersVoidResult = {
@ -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. /** Clamps a value into the given bounds.
This functions is equivalent to $(D max(lower, min(upper,val))). This functions is equivalent to $(D max(lower, min(upper,val))).