!in

Michel Fortin michel.fortin at michelf.com
Wed Feb 17 09:46:10 PST 2010


On 2010-02-17 12:07:05 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> Searching a value in a literal should actually be allowed:
> 
> x in [10, 20, 30, 0]
> 
> is great because the compiler has complete discretion in how to conduct 
> the search (e.g. linear vs. binary vs. hash search; it can take the 
> initiative of presorting the literal). But general search in an 
> unstructured range... maybe not.

Are you talking about literals or compile-time constants? A literal can 
be built using variables and functions, such as:

	x in [a, b, c, d, e]

This would be mostly equivalent to this:

	x == a || x == b || x == c || x == d || x == e

I'd tend to allow it as it makes it easier to write and read 
conditionals with repeated comparisons against the same variable.

But I guess that's less important than supporting compile-time constants:

	const allowedCharacters = ['0','1','2','3','4','5','6','7','8','9'];

	if (x in allowedCharacters)
		...;


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list