www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why type specialization is defined differently than is expression

reply deadalnix <deadalnix gmail.com> writes:
All is in the title.

I can do is(T : class) but not template(T : class) . Is this intended or 
is it because it is ?
Jun 27 2012
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this intended or
 is it because it is ?

You cannot do is(T : class).
Jun 27 2012
next sibling parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <alex lycus.org> writes:
On 27-06-2012 19:13, Timon Gehr wrote:
 On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this intended or
 is it because it is ?

You cannot do is(T : class).

I think what's really worrying is that this is legal: void foo(T : class)() { } But this is not: template Foo(T : class) { } -- Alex Rønne Petersen alex lycus.org http://lycus.org
Jun 27 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/27/2012 08:21 PM, Alex Rønne Petersen wrote:
 On 27-06-2012 19:13, Timon Gehr wrote:
 On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this intended or
 is it because it is ?

You cannot do is(T : class).

I think what's really worrying is that this is legal: void foo(T : class)() { }

This is not legal.
 But this is not:

 template Foo(T : class)
 {
 }

Jun 27 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 19:23:07 UTC, Timon Gehr wrote:
 This is not legal.

Template type specialization must have a basic type after colon. s/class/Object should make it legal. By the way, it is not possible to specialize for structs this way, is it? I mean, via template type specialization, not via template constraints.
Jun 27 2012
prev sibling next sibling parent reply "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 17:13:10 UTC, Timon Gehr wrote:
 On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this 
 intended or
 is it because it is ?

You cannot do is(T : class).

Why? According to grammar, IsExpression: is ( Type : TypeSpecialization ) and TypeSpecialization: Type struct union class interface enum function delegate super const immutable inout shared return
Jun 27 2012
parent deadalnix <deadalnix gmail.com> writes:
Le 27/06/2012 22:35, Steven Schveighoffer a écrit :
 On Wed, 27 Jun 2012 16:32:33 -0400, Roman D. Boiko <rb d-coding.com> wrote:

 On Wednesday, 27 June 2012 at 20:27:39 UTC, Steven Schveighoffer wrote:
 On Wed, 27 Jun 2012 16:16:53 -0400, Roman D. Boiko <rb d-coding.com>
 wrote:
 TypeSpecialization:

 Type struct union class interface enum function delegate super
 const immutable inout shared return


This is only valid for is( Type == TypeSpecialization)

No, unless the D specification is outdated. IsExpression: is ( Type ) is ( Type : TypeSpecialization ) is ( Type == TypeSpecialization ) ...

It's poorly written, TypeSpecialization is restricted for the : case. Maybe it passes the parser, but fails on semantic. "TypeSpecialization is only allowed to be a Type." -- context for is(Type : TypeSpecialization) -Steve

OK, I had misunderstood here too. This whole is stuff is kind of messed up.
Jun 27 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 20:15:43 UTC, Roman D. Boiko wrote:
 On Wednesday, 27 June 2012 at 17:13:10 UTC, Timon Gehr wrote:
 On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this 
 intended or
 is it because it is ?

You cannot do is(T : class).

Why? According to grammar, IsExpression: is ( Type : TypeSpecialization ) and TypeSpecialization: Type struct union class interface enum function delegate super const immutable inout shared return

Sorry, I read like typeof(T): is(typeof(T):class)
Jun 27 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 27 Jun 2012 16:16:53 -0400, Roman D. Boiko <rb d-coding.com> wrote:

 On Wednesday, 27 June 2012 at 20:15:43 UTC, Roman D. Boiko wrote:
 On Wednesday, 27 June 2012 at 17:13:10 UTC, Timon Gehr wrote:
 On 06/27/2012 03:56 PM, deadalnix wrote:
 All is in the title.

 I can do is(T : class) but not template(T : class) . Is this intended  
 or
 is it because it is ?

You cannot do is(T : class).

Why? According to grammar, IsExpression: is ( Type : TypeSpecialization ) and


The condition is satisfied if Type is semantically correct and it is the same as or can be implicitly converted to TypeSpecialization.
TypeSpecialization is only allowed to be a Type.<<<



Emphasis added.
 TypeSpecialization:

 Type struct union class interface enum function delegate super const  
 immutable inout shared return


This is only valid for is( Type == TypeSpecialization) -Steve
Jun 27 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 20:27:39 UTC, Steven Schveighoffer 
wrote:
 On Wed, 27 Jun 2012 16:16:53 -0400, Roman D. Boiko 
 <rb d-coding.com> wrote:
 TypeSpecialization:

 Type struct union class interface enum function delegate 
 super const immutable inout shared return


This is only valid for is( Type == TypeSpecialization)

No, unless the D specification is outdated. IsExpression: is ( Type ) is ( Type : TypeSpecialization ) is ( Type == TypeSpecialization ) ...
Jun 27 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 20:32:34 UTC, Roman D. Boiko wrote:
 On Wednesday, 27 June 2012 at 20:27:39 UTC, Steven 
 Schveighoffer wrote:
 On Wed, 27 Jun 2012 16:16:53 -0400, Roman D. Boiko 
 <rb d-coding.com> wrote:
 TypeSpecialization:

 Type struct union class interface enum function delegate 
 super const immutable inout shared return


This is only valid for is( Type == TypeSpecialization)

No, unless the D specification is outdated. IsExpression: is ( Type ) is ( Type : TypeSpecialization ) is ( Type == TypeSpecialization ) ...

Ups... Seems I implemented this incorrectly. Indeed, below there is a note: TypeSpecialization is only allowed to be a Type.
Jun 27 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 27 Jun 2012 16:32:33 -0400, Roman D. Boiko <rb d-coding.com> wrote:

 On Wednesday, 27 June 2012 at 20:27:39 UTC, Steven Schveighoffer wrote:
 On Wed, 27 Jun 2012 16:16:53 -0400, Roman D. Boiko <rb d-coding.com>  
 wrote:
 TypeSpecialization:

 Type struct union class interface enum function delegate super const  
 immutable inout shared return


This is only valid for is( Type == TypeSpecialization)

No, unless the D specification is outdated. IsExpression: is ( Type ) is ( Type : TypeSpecialization ) is ( Type == TypeSpecialization ) ...

It's poorly written, TypeSpecialization is restricted for the : case. Maybe it passes the parser, but fails on semantic. "TypeSpecialization is only allowed to be a Type." -- context for is(Type : TypeSpecialization) -Steve
Jun 27 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 20:35:47 UTC, Steven Schveighoffer 
wrote:
 On Wed, 27 Jun 2012 16:32:33 -0400, Roman D. Boiko 
 <rb d-coding.com> wrote:

 It's poorly written, TypeSpecialization is restricted for the : 
 case.  Maybe it passes the parser, but fails on semantic.

 "TypeSpecialization is only allowed to be a Type." -- context 
 for is(Type : TypeSpecialization)

Yeah, I found that after your post. Probably it was easier to implement an IsExpression in a unified way and check semantics separately. Otherwise it would be that IsExpression have to contain different types of members, if Type (not TypeSpecialization) in the `:` case, and the latter in the `TypeSpecialization` case.
Jun 27 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 27 Jun 2012 16:40:47 -0400, Roman D. Boiko <rb d-coding.com> wrote:

 On Wednesday, 27 June 2012 at 20:35:47 UTC, Steven Schveighoffer wrote:
 On Wed, 27 Jun 2012 16:32:33 -0400, Roman D. Boiko <rb d-coding.com>  
 wrote:

 It's poorly written, TypeSpecialization is restricted for the : case.   
 Maybe it passes the parser, but fails on semantic.

 "TypeSpecialization is only allowed to be a Type." -- context for  
 is(Type : TypeSpecialization)

Yeah, I found that after your post. Probably it was easier to implement an IsExpression in a unified way and check semantics separately. Otherwise it would be that IsExpression have to contain different types of members, if Type (not TypeSpecialization) in the `:` case, and the latter in the `TypeSpecialization` case.

Hm... come to think of it, shouldn't TypeSpecialization be Type instead? Seems weird to say Type : TypeSpecialization, and then say "TypeSpecialization is only allowed to be Type". Why not Type : Type? -Steve
Jun 27 2012
prev sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Wednesday, 27 June 2012 at 20:42:39 UTC, Steven Schveighoffer 
wrote:
 Hm... come to think of it, shouldn't TypeSpecialization be Type 
 instead?

 Seems weird to say Type : TypeSpecialization, and then say 
 "TypeSpecialization is only allowed to be Type".  Why not Type 
 : Type?

That's what I was trying to explain. It is probably easier to implement an IsExpression this way, because it would always contain members of the same types. Also, I made a typo, should be:
 and TypeSpecialization in the `==` case.

Jun 27 2012