www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: shortcut for dynamic dispatch and operators

reply bearophile <bearophileHUGS lycos.com> writes:
KennyTM~:
 Make "x in y" returns a bool and works for arrays.

That's something more useful than the sum of usefulness of opDispatch, opPow and opLength. You use it all the time in code, and in D it's even more useful than in Python because in D a small linear scan can be very fast. To do that in my dlibs I use the function isIn(item, items), where items can be an AA too of course. Bye, bearophile
Dec 01 2009
parent =?UTF-8?B?UGVsbGUgTcOlbnNzb24=?= <pelle.mansson gmail.com> writes:
bearophile wrote:
 KennyTM~:
 Make "x in y" returns a bool and works for arrays.

That's something more useful than the sum of usefulness of opDispatch, opPow and opLength. You use it all the time in code, and in D it's even more useful than in Python because in D a small linear scan can be very fast. To do that in my dlibs I use the function isIn(item, items), where items can be an AA too of course. Bye, bearophile

the time. compare: if (x in [1, 2, 3]) { } if (x == 1 || x == 2 || x == 3) { } I find the first one prettier. :)
Dec 01 2009