std.sumtype?
Paul Backus
snarwin at gmail.com
Mon Mar 22 21:43:58 UTC 2021
On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
> Does anyone know if it would be possible to make it support (it
> doesn't support it now) this kind of syntax:
>
> Temperature t1 = Fahrenheit(98.6);
> isFahrenheit(t1); // works
> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(
You can do this by adding an additional overload to isFahrenheit:
bool isFahrenheit(T)(T t)
if (staticIndexOf!(T, Temperature.Types) >= 0)
{
return is(T == Fahrenheit);
}
bool isFahrenheit(Temperature temp)
{
// Forward to template overload
return temp.match!isFahrenheit;
}
More information about the Digitalmars-d
mailing list