between and among: worth Phobosization?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 17 10:12:10 PST 2013


On 12/17/13 7:59 AM, Jerry wrote:
> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> writes:
>
>> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
>> {
>>      return v >= lo && v <= hi;
>> }
>
> +1
>
>> uint among(T, Us...)(T v, Us vals)
>> {
>>      foreach (i, U; Us)
>>      {
>>          if (v == vals[i]) return i + 1;
>>      }
>>      return 0;
>> }
>
> This seems less useful to me.  What was the example where you found it
> useful?
>
> Jerry

I gave a long litany of examples taken from real code in a subsequent 
post. In fact I couldn't find motivating examples for "between", or even 
significant evidence that it would be dramatically useful; I'd included 
it only for completion, and I have since retracted it.

Andrei



More information about the Digitalmars-d mailing list