Comparing Multiple Values
BCS
ao at pathlink.com
Tue Mar 11 09:53:50 PDT 2008
Reply to Derek,
> On Tue, 11 Mar 2008 13:39:55 +0100, downs wrote:
>
>> There's a better way actually.
>>
> But that is only good for ranges ;-)
>
> Not so good for ...
>
> if value in set(2,4,7,10,23,445)
>
> I'm pretty sure this will be simple to organize once AST macros are
> implemented.
>
struct _Set(T) {
T[] set;
bool opIn_r(U)(U u) {
foreach(v; set) if(v==u) return true;
return false;
}
}
struct Set {
static _Set!(T) opIndex(T, U)(T[] a...) {
_Set!(T) ret;
ret.set = a.dup; //need the dup???
return ret;
}
}
I /think/ that will work. But I haven't tested it.
if(1 in Set[1,2,3,5,9,23])
More information about the Digitalmars-d-learn
mailing list