September 25, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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. "is(R == typeof(takeExactly(R, 1)))" Makes sure they are the exact same type, and "is(typeof(takeExactly(R, 1)))" is a short-circuit, to prevent the second test from error'ing if takeExactly!R is not legal. |
September 26, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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));
|
September 26, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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?
|
September 26, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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.
|
September 26, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On 9/26/12 9:50 AM, monarch_dodra wrote:
> 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
Neither should work. The expression should be takeExactly(S.init, 1).
Andrei
|
September 26, 2012 Re: Testing for template argument being result of takeExactly | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 09/26/2012 05:08 PM, Andrei Alexandrescu wrote: > On 9/26/12 9:50 AM, monarch_dodra wrote: >> 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 > > Neither should work. The expression should be takeExactly(S.init, 1). > > Andrei http://d.puremagic.com/issues/show_bug.cgi?id=8220 https://github.com/D-Programming-Language/dmd/pull/1007 |
Copyright © 1999-2021 by the D Language Foundation