Testing for template argument being result of takeExactly

Jonathan M Davis jmdavisProg at gmx.com
Mon Sep 24 00:07:56 PDT 2012


On Monday, September 24, 2012 08:21:46 monarch_dodra wrote:
> template Hello(R)
>      if ( is(typeof(takeExactly(R.init, 1))) &&
>           is(R == typeof(takeExactly(R.init, 1)))
>      )
> {
>      alias R Hello;
> }

> What is wrong with my proposed solution?

It may work, but again, it's relying on how takeExactly works. It's testing 
that you can call takeExactly on R.init and then that R is the same type as 
that result, which means that it's relies on the fact that takeExactly returns 
itself if you call takeExactly on it. It also relies on init, which can be 
risky, given the fact that it can be disabled.

So, between your prosposal and the other that Philippe and Timon gave, theirs 
seems better. But unfortunately, none of the proposals work generically. 
Ideally, there would be a way to generically test that a type is the type 
returned by particular function, and I would _think_ that that's possible, but 
the way that I would expect to work doesn't.

Regardless, thanks for your help.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list