Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Last active August 29, 2015 13:57
Show Gist options
  • Save volgar1x/9492604 to your computer and use it in GitHub Desktop.
Save volgar1x/9492604 to your computer and use it in GitHub Desktop.
static if (is (T == float)) {
alias ResultType = double;
} else static if (is (T == double)) {
alias ResultType = real;
} else {
static assert(false, T.stringof ~ " is not supported");
}
cast(Type)var
alias ResultType =
if (T is float) double
else if (T is double) real
else assert(false, "${T.stringof} is not supported")
;
alias ResultType = match(T) {
float -> double
real -> real
/* match doesn't apply to other types: automatically fails */
}
cast!Type(var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment