Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread John Colvin via Digitalmars-d-learn

On Monday, 11 August 2014 at 18:21:04 UTC, Baz wrote:
Hi, I try to get why the last way of generating an interface 
implementation fails. I've put assumptions: is it right ?

---
module itfgen;

import std.stdio;

interface itf{
void a_int(int p);
void a_uint(uint p);
}

class impl3: itf{
void tmp(T)(T p){};
alias a_int = tmp!int;
alias a_uint = tmp!uint;
}


Part of me feels that ought to work. There may well be good 
reasons why not though.


Currently you do have to have method implementations/overrides 
written out as normal functions.


Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread anonymous via Digitalmars-d-learn

On Monday, 11 August 2014 at 18:21:04 UTC, Baz wrote:

interface itf{
void a_int(int p);
void a_uint(uint p);
}

[...]
// FAILS because: alias are probably generated after the itf 
check

class impl3: itf{
void tmp(T)(T p){};
alias a_int = tmp!int;
alias a_uint = tmp!uint;
}

[...]
'Error: class itfgen.impl3 interface function 'void a_int(int 
p)' is not implemented'.


I think the problem is that impl3.tmp is not virtual because it's
a template, and interfaces need to be implemented by virtual
methods.


Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread John Colvin via Digitalmars-d-learn

On Tuesday, 12 August 2014 at 11:34:01 UTC, anonymous wrote:

On Monday, 11 August 2014 at 18:21:04 UTC, Baz wrote:

interface itf{
   void a_int(int p);
   void a_uint(uint p);
}

[...]
// FAILS because: alias are probably generated after the itf 
check

class impl3: itf{
   void tmp(T)(T p){};
   alias a_int = tmp!int;
   alias a_uint = tmp!uint;
}

[...]
'Error: class itfgen.impl3 interface function 'void a_int(int 
p)' is not implemented'.


I think the problem is that impl3.tmp is not virtual because 
it's

a template, and interfaces need to be implemented by virtual
methods.


The instantiations of the template are just normal functions 
though, no?


Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread anonymous via Digitalmars-d-learn

On Tuesday, 12 August 2014 at 12:08:14 UTC, John Colvin wrote:
I think the problem is that impl3.tmp is not virtual because 
it's

a template, and interfaces need to be implemented by virtual
methods.


The instantiations of the template are just normal functions 
though, no?


They are not virtual. Ordinary methods (public, not final, not
templated) are virtual.


Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread Baz via Digitalmars-d-learn

On Tuesday, 12 August 2014 at 12:43:46 UTC, anonymous wrote:

On Tuesday, 12 August 2014 at 12:08:14 UTC, John Colvin wrote:
I think the problem is that impl3.tmp is not virtual because 
it's

a template, and interfaces need to be implemented by virtual
methods.


The instantiations of the template are just normal functions 
though, no?


They are not virtual. Ordinary methods (public, not final, not
templated) are virtual.


The virtual stuff is right. I've just realized that it's written 
black on white at the bottom of the manual page which describes 
templates:


Templates cannot be used to add non-static members or virtual 
functions to classes

Templates cannot add functions to interfaces

Sorry for the loss of time.



Destroy two assumptions: interface implementation generated by TMP

2014-08-11 Thread Baz via Digitalmars-d-learn
Hi, I try to get why the last way of generating an interface 
implementation fails. I've put assumptions: is it right ?

---
module itfgen;

import std.stdio;

interface itf{
void a_int(int p);
void a_uint(uint p);
}

template genimpl(T){
char[] genimpl(){
char[] result;
result = void a_ ~ T.stringof ~ (~ T.stringof ~  
p){}.dup;

return result;
}
}

class impl: itf{
mixin(genimpl!int);
mixin(genimpl!uint);
}

// OK because: mixin is at the source code level, begining of the 
ana

class impl2: itf{
static char[] genimplint(T)(){
char[] result;
result = void a_ ~ T.stringof ~ (~ T.stringof ~  
p){}.dup;

return result;
}
mixin(genimplint!int);
mixin(genimplint!uint);
}

// FAILS because: alias are probably generated after the itf check
class impl3: itf{
void tmp(T)(T p){};
alias a_int = tmp!int;
alias a_uint = tmp!uint;
}

void main(string args[]){
auto I1 = new impl;
auto I2 = new impl2;
auto I3 = new impl3;
}
---

I get

'Error: class itfgen.impl3 interface function 'void a_int(int p)' 
is not implemented'.