Testing for template argument being result of takeExactly

Timon Gehr timon.gehr at gmx.ch
Wed Sep 26 06:19:56 PDT 2012


On 09/25/2012 08:41 AM, monarch_dodra wrote:
> On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote:
>> On 09/24/2012 09:41 AM, monarch_dodra wrote:
>> > [SNIP]
>>
>> I don't think this does what you think it does. The 'is(R r)' declares
>> r to be an alias for R. So 'r' is a type in that code snippet.
>
> Darn :(
>
>> Also, is(typeof(takeExactly(R, 1))) && is(R == typeof(takeExactly(R, 1)))
>>
>> can be written in a more compact way as
>>
>> is(typeof(takeExactly(R, 1)) == R)
>>
> Technically, no: That was my first try, and as mentioned in the first
> reply, this returns true when the types of takeExactly and R are equal
> comparable, but does not make sure they are the actually the same types.
> ...

I assume you messed up the parentheses.

is(typeof(takeExactly(R, 1) == R)) // test for equal-comparable
is(typeof(takeExactly(R, 1)) == R) // test for type identity

alias float flt;
static assert(is(typeof(1==flt)));
static assert(!is(typeof(1)==flt));


More information about the Digitalmars-d-learn mailing list