between and among: worth Phobosization?
bearophile
bearophileHUGS at lycos.com
Mon Dec 16 13:13:57 PST 2013
Andrei Alexandrescu:
> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
> {
> return v >= lo && v <= hi;
> }
I vote a +1 for between(). One use case:
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Stronger_Statically_Typed_Version
It also helps in the D translation of Python expressions like:
if foo() and 3 < bar(x) < 5 and ...:
That in D need to be split in more lines unless bar() is pure and
light.
-----------------
Regarding Phobos, currently one of the features I miss mostly is
an optional template function for the min and max functions:
https://d.puremagic.com/issues/show_bug.cgi?id=4705#c16
Bye,
bearophile
More information about the Digitalmars-d
mailing list