On 5/11/12 5:43 PM, Timon Gehr wrote:
On 05/11/2012 10:29 PM, Jonathan M Davis wrote:
On Friday, May 11, 2012 21:02:46 Alex Rønne Petersen wrote:
On 11-05-2012 20:34, Mehrdad wrote:
On Friday, 11 May 2012 at 18:25:17 UTC, Jonathan M Davis wrote:
Actually, that is a WAT even for somebody coming from C/C++.
Really? That's pretty much exactly what I would have expected, and it
would
really suck if it returned a bool. It's like what you get with find on
std::map, only it's a pointer instead of an iterator.
- Jonathan M Davis
Again, try to see it from the perspective of a Python user, not a
C++ user.
Speaking of which, 'in' on arrays.........
*hint hint*
Except that it would break the generally expected algoritmic
complexity of in,
so it'll never happen ( O(n) for arrays, whereas the worst case that
would be
acceptable would be O(lg n) - e.g. what a binary tree could achieve).
- Jonathan M Davis
The main use case I see is replacing tedious
if(foo == 'a' || foo == 'b' || foo == 'c' || foo == 'd') { ... }
with
if(foo in "abcd") { .... }
And here the counter-argument cannot apply, because the operation is in
O(1).
Yes, "in" for statically-sized arrays does make sense because the
complexity if bound at compilation time.
Andrei