December 17, 2005
Bruno Medeiros wrote:
> 
> Yes, the other examples have some good ideias. However, as for this one here:
> http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample
> Is that not incorrect?

That is incorrect.  Though I think templates can not add virtual members to classes (ie. I believe template methods are implicitly final). Though I have not tested this to be sure.


Sean
December 17, 2005
"Sean Kelly" <sean@f4.ca> wrote in message news:do1ig2$1ekh$1@digitaldaemon.com...
> Bruno Medeiros wrote:
>>
>> Yes, the other examples have some good ideias. However, as for this one here: http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample Is that not incorrect?
>
> That is incorrect.  Though I think templates can not add virtual members to classes (ie. I believe template methods are implicitly final). Though I have not tested this to be sure.
>
>
> Sean

Though the spec says a mixin *can* add virtual functions to a class. That said, I recently encountered a problem whereby a class method refused to override the templated version.


December 17, 2005
John C wrote:
> "Sean Kelly" <sean@f4.ca> wrote in message news:do1ig2$1ekh$1@digitaldaemon.com...
>> Bruno Medeiros wrote:
>>> Yes, the other examples have some good ideias. However, as for this one here:
>>> http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample
>>> Is that not incorrect?
>> That is incorrect.  Though I think templates can not add virtual members to classes (ie. I believe template methods are implicitly final). Though I have not tested this to be sure.
>>
>>
>> Sean
> 
> Though the spec says a mixin *can* add virtual functions to a class. That said, I recently encountered a problem whereby a class method refused to override the templated version. 

I think this might work:

class C
{
	template fn(T) {
		void fn( T val ) {}
	}
	alias fn!(char) charFn;
}

class D : C {
	override void charFn() {}
}


Sean
December 18, 2005
In article <do113n$135m$1@digitaldaemon.com>, Bruno Medeiros says...
>
>Yes, the other examples have some good ideias. However, as for this one here: http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample Is that not incorrect? The spec clearly states (http://www.digitalmars.com/d/template.html) that "Templates cannot be used to add non-static members" to classes. This is precisely what that example does, and the funny thing is that it compiles and runs ok. I don't see how that can work, unless the compiler is treating the templated method as final.
>

I expanded that example a bit to use inheritance and it looks like the documentation is wrong... Not only are the functions non-static and non-final but are (correctly) virtual as well.

Walter?

- Dave

>
>-- 
>Bruno Medeiros - CS/E student
>"Certain aspects of D are a pathway to many abilities some consider to
>be... unnatural."


December 19, 2005
Dave wrote:
> In article <do113n$135m$1@digitaldaemon.com>, Bruno Medeiros says...
> 
>>Yes, the other examples have some good ideias. However, as for this one here:
>>http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample
>>Is that not incorrect? The spec clearly states (http://www.digitalmars.com/d/template.html) that "Templates cannot be used to add non-static members" to classes. This is precisely what that example does, and the funny thing is that it compiles and runs ok. I don't see how that can work, unless the compiler is treating the templated method as final.
>>
> 
> 
> I expanded that example a bit to use inheritance and it looks like the
> documentation is wrong... Not only are the functions non-static and non-final
> but are (correctly) virtual as well.
> 
> Walter?
> 
> - Dave
> 
How did you test that? Because it's not correct, they are not virtual.
First of all, the existance of the inner template declaration and/or inner template instances does not change the size of the class vtable.
Second, this test:

  class FooA {
      template as() {
          void func() {
              writefln("FooA func()");
          }
      }
  }

  class FooB : FooA {
      template as() {
          void func() {
              writefln("FooB func()");
          }
      }
  }

  int main(char[][] args)
  {
  //	writefln(FooA.classinfo.vtbl.length);

  	FooA foob = new FooB();
  	foob.as!().func();  // calls FooA.as!().func()
  }

shows that the templated function is not virtual. It's not possible otherwise. So it's a compiler bug (should give an error unless templated function(s) are declared as final).


-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
December 19, 2005
In article <do6af9$2nd$1@digitaldaemon.com>, Bruno Medeiros says...
>
>Dave wrote:
>> In article <do113n$135m$1@digitaldaemon.com>, Bruno Medeiros says...
>> 
>>>Yes, the other examples have some good ideias. However, as for this one here: http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample Is that not incorrect? The spec clearly states (http://www.digitalmars.com/d/template.html) that "Templates cannot be used to add non-static members" to classes. This is precisely what that example does, and the funny thing is that it compiles and runs ok. I don't see how that can work, unless the compiler is treating the templated method as final.
>>>
>> 
>> 
>> I expanded that example a bit to use inheritance and it looks like the documentation is wrong... Not only are the functions non-static and non-final but are (correctly) virtual as well.
>> 
>> Walter?
>> 
>> - Dave
>> 
>How did you test that? Because it's not correct, they are not virtual. First of all, the existance of the inner template declaration and/or inner template instances does not change the size of the class vtable. Second, this test:
>
>   class FooA {
>       template as() {
>           void func() {
>               writefln("FooA func()");
>           }
>       }
>   }
>
>   class FooB : FooA {
>       template as() {
>           void func() {
>               writefln("FooB func()");
>           }
>       }
>   }
>
>   int main(char[][] args)
>   {
>   //	writefln(FooA.classinfo.vtbl.length);
>
>   	FooA foob = new FooB();
>   	foob.as!().func();  // calls FooA.as!().func()
>   }
>
>shows that the templated function is not virtual. It's not possible otherwise. So it's a compiler bug (should give an error unless templated function(s) are declared as final).
>

You're right about the virtual - I misinterpreted my results.

Declaring them final isn't correct though, because the compiler can't enforce that for the same reason it isn't making them virtual in the first place. In other words, if it could enforce final by checking for overridden functions, then why not make them virtual as well?

So it looks like the docs. are correct as-is, *but* the compiler has to change to enforce the use of 'static' for this case.


December 20, 2005
Dave wrote:
> In article <do6af9$2nd$1@digitaldaemon.com>, Bruno Medeiros says...
> 
>>Dave wrote:
>>
>>>In article <do113n$135m$1@digitaldaemon.com>, Bruno Medeiros says...
>>>
>>>
>>>>Yes, the other examples have some good ideias. However, as for this one here:
>>>>http://trac.dsource.org/projects/tutorials/wiki/InternalTemplatesExample
>>>>Is that not incorrect? The spec clearly states (http://www.digitalmars.com/d/template.html) that "Templates cannot be used to add non-static members" to classes. This is precisely what that example does, and the funny thing is that it compiles and runs ok. I don't see how that can work, unless the compiler is treating the templated method as final.
>>>>
>>>
>>>
>>>I expanded that example a bit to use inheritance and it looks like the
>>>documentation is wrong... Not only are the functions non-static and non-final
>>>but are (correctly) virtual as well.
>>>
>>>Walter?
>>>
>>>- Dave
>>>
>>
>>How did you test that? Because it's not correct, they are not virtual.
>>First of all, the existance of the inner template declaration and/or inner template instances does not change the size of the class vtable.
>>Second, this test:
>>
>>  class FooA {
>>      template as() {
>>          void func() {
>>              writefln("FooA func()");
>>          }
>>      }
>>  }
>>
>>  class FooB : FooA {
>>      template as() {
>>          void func() {
>>              writefln("FooB func()");
>>          }
>>      }
>>  }
>>
>>  int main(char[][] args)
>>  {
>>  //	writefln(FooA.classinfo.vtbl.length);
>>
>>  	FooA foob = new FooB();
>>  	foob.as!().func();  // calls FooA.as!().func()
>>  }
>>
>>shows that the templated function is not virtual. It's not possible otherwise. So it's a compiler bug (should give an error unless templated function(s) are declared as final).
>>
> 
> 
> You're right about the virtual - I misinterpreted my results.
> 
> Declaring them final isn't correct though, because the compiler can't enforce
> that for the same reason it isn't making them virtual in the first place. In
> other words, if it could enforce final by checking for overridden functions,
> then why not make them virtual as well?
> 
Hum, you're right, they're not final either, they're just non-virtual. (This is the only way to create such "rogue" functions, AFAIK.)


> So it looks like the docs. are correct as-is, *but* the compiler has to change
> to enforce the use of 'static' for this case.
> 



-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
1 2 3
Next ›   Last »