Dual conditions in D and Python

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 14:35:21 PDT 2015


On 05/21/2015 12:44 PM, Meta wrote:

> All we need is user-defined opIs and then we're really cooking with gas.
>
> if (5 is between(4, 6))
> {
>      //...
> }
>

We're almost there. :)

bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max)
{
     return (what >= min) && (what <= max);
}

void main()
{
     if (5.is_between(4, 6)) {
         // ...
     }
}

Ali



More information about the Digitalmars-d-learn mailing list