in operator generalization
Stewart Gordon
smjg_1998 at yahoo.com
Mon Mar 20 03:34:58 PST 2006
Les Baker wrote:
> Looking through old NG posts I found this one by Ben Hinkle last year
> about extending the "in" operator to support static/dynamic arrays.
>
> http://www.digitalmars.com/d/archives/digitalmars/D/25164
<snip>
There are two problems with that proposal:
1. At the moment, the only use of the in operator is to determine
whether a key is present in an AA. Logically, therefore, for linear arrays,
x in y
should report on whether x is an index within the bounds of y, i.e.
x >= 0 && x < y.length
This has been talked about before:
http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/6082
2. The result of the in operator is designed to be directly usable as a
boolean value and to do what it says on the tin when used as such.
Making it return an index, instead of a pointer as in for AAs does,
screws this up totally. As such, under Ben's proposal
if (x in y)
would be equivalent to
if (y.length != 0 && y[0] != x)
which is well and truly counter-intuitive.
Stewart.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS-
PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
More information about the Digitalmars-d
mailing list