Is it possible to store properties via opDispatch using tuples?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 17 13:14:54 PST 2014


On Fri, Jan 17, 2014 at 09:08:50PM +0100, Jacob Carlborg wrote:
> On 2014-01-17 18:49, H. S. Teoh wrote:
> 
> >Now I'm not sure if Variant allows assignment to a static type, but
> >in theory this should be possible:
> >
> >	// assume d.abc returns a Variant
> >	int x = d.abc; // will assert if d.abc doesn't hold an int at runtime
> 
> It doesn't work. Variant doesn't retain the static type, which is
> needed in this case.
[...]

Is that because D doesn't have implicit casting via opCast? -- because,
conceivably, if

	x = d.abc;
	
gets lowered to

	x = d.opCast!(typeof(x))(d.abc);
	
then the above can be made to work.


T

-- 
If you look at a thing nine hundred and ninety-nine times, you are perfectly safe; if you look at it the thousandth time, you are in frightful danger of seeing it for the first time. -- G. K. Chesterton


More information about the Digitalmars-d-learn mailing list