My thoughts & experiences with D so far, as a novice D coder

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Mar 27 10:06:48 PDT 2013


On Wed, Mar 27, 2013 at 05:04:48PM +0100, bearophile wrote:
[...]
> >- When casting a value to an enum, there's no checking that the
> >value actually is a valid enum value. Don't think I ever found a
> >solution on how to check whether the value after casting is a
> >valid enum value, it hasn't been a pressing issue.
> 
> cast() is a sharp unsafe tool. In Bugzilla I have a request to use
> to!() to perform that safely.
[...]

It already does that on latest git phobos:

	enum A { abc=100, def=200 }
	A a;
	a = to!A(150);	// throws runtime exception


T

-- 
All problems are easy in retrospect.


More information about the Digitalmars-d mailing list