On Monday, 24 September 2012 at 07:07:16 UTC, Jonathan M Davis
wrote:
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
Good points.
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;
}
--------
After that, I guess it is indeed one implementation detail vs the
other.
IMO, it really depends on whether or not you'd want "int[]" to be
considered the return type of a takeExactly :/ Maybe it is, maybe
it ain't.