Dual conditions in D and Python
Andrei Alexandrescu via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 23 10:17:17 PDT 2015
On 5/21/15 2:35 PM, Ali Çehreli wrote:
> 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)) {
> // ...
> }
> }
In fact we'll be there with 2.068:
http://dlang.org/phobos-prerelease/std_algorithm_sorting.html#.ordered
if (ordered(4, 5, 6)) { ... }
if (strictlyOrdered(4, 5, 6)) { ... }
Andrei
More information about the Digitalmars-d-learn
mailing list