'in' for arrays?

Alexander Panek a.panek at brainsware.org
Wed Dec 6 07:50:41 PST 2006


Ha! Very nice.

I start to like those mysterious Tuples. ;)

Jarrett Billingsley wrote:
> "Egor Starostin" <egorst at gmail.com> wrote in message 
> news:el5vpc$9nt$1 at digitaldaemon.com...
>> Me too.
>>
>> For example, in Python I can write
>>
>> if val in ('off','disable','no')
>>
>> and in D I have to write
>>
>> if (val == "off" || val == "disable" || val == "no")
>>
>> which is less readable (to me, at least).
> 
> struct _Tuple(T...)
> {
>  bool opIn_r(U)(U value)
>  {
>   foreach(val; T)
>   {
>    static if(is(typeof(val) : U))
>    {
>     if(val == value)
>      return true;
>    }
>   }
> 
>   return false;
>  }
> }
> 
> template Tuple(T...)
> {
>  const _Tuple!(T) Tuple;
> }
> 
> void main()
> {
>  if(4 in Tuple!("hi", 5.5, 4))
>   writefln("yep");
>  else
>   writefln("nope");
> 
>  if("no" in Tuple!("hi", 5.5, 4))
>   writefln("yep");
>  else
>   writefln("nope");
> }
> 
> 
> Meh.  :) 
> 
> 



More information about the Digitalmars-d mailing list