Testing for template argument being result of takeExactly

Timon Gehr timon.gehr at gmx.ch
Wed Sep 26 07:27:10 PDT 2012


On 09/26/2012 03:50 PM, monarch_dodra wrote:
> On Wednesday, 26 September 2012 at 13:19:13 UTC, Timon Gehr wrote:
>> 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));
>
> Yes sorry. I miss read that.
>
> Kind of weird though, could you explain why:
>
> struct S{};
>
> is(typeof(takeExactly(S, 1)) == S) //false
> is(S == typeof(takeExactly(S, 1))) //Error: template
> std.range.takeExactly does not match any function template declaration
>
> I was under the understanding that == was a commutative operation. Not
> the case in an is block?

It is special syntax, not an == operator. is-expressions suppress errors
in the first argument only.


More information about the Digitalmars-d-learn mailing list