Testing for template argument being result of takeExactly

Jonathan M Davis jmdavisProg at gmx.com
Mon Sep 24 00:52:03 PDT 2012


On Monday, September 24, 2012 09:41:26 monarch_dodra wrote:
> Regarding the ".init" issue, I hadn't thought of that, but it can
> be worked around pretty easily with an is(R r):
> 
> --------
> template Hello(R)
>       if ( is(R r) &&
>            is(typeof(takeExactly(r, 1))) &&
>            is(R == typeof(takeExactly(r, 1)))
>       )
> {
>       alias R Hello;
> }
> --------

That was one trick that I was not aware of. I didn't think that one is 
expression could have an effect on a later one in the surrounding expression. 
Cool. Though I would point out that that probably doesn't avoid the init 
problem, because R r uses R.init (unless is expressions treat it differently, 
which they may). The normal way to avoid that is to do

R r = void;

but I don't think that that would work in that is expression. Sometimes 
disabling init is useful, but it can definitely be problematic. It may 
ultimately have been a mistake to allow it. I don't know.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list