D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1433 - in array / slice / range / enum / ...
Summary: in array / slice / range / enum / ...
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2007-08-19 17:38 UTC by Christian Hartung
Modified: 2017-09-19 09:52 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Christian Hartung 2007-08-19 17:38:30 UTC
The in expression can be extended to support things like:

int i;
...

if(i in [1, 2, 3])

or

if(i in [1..5])

or even

enum Color { red, blue, green };
if(i in Color)

It will test for the existence of the element in the container, returning true if the element is found. If the container is a set of integers, the element must be an integer. If the set is a string, the element must be a char..
An !in expression also is welcome.

Obs.: also keep the current in expression for associative arrays, returning a pointer to the element and the opIn and opIn_r.
Comment 1 bearophile_hugs 2011-08-20 03:53:18 UTC
As alternative see bug 6536
Comment 2 Infiltrator 2014-03-19 20:18:58 UTC
Since the general sentiment is that using in like this, with different semantics, is a bad idea, should this be closed off?
Comment 3 Simen Kjaeraas 2017-09-19 09:52:09 UTC
It's generally agreed that in's semantics makes this kind of use problematic, and different solution should be preferred. These include std.algorithm.among and canFind.