Template method and overloading

Daniel Keep daniel.keep.lists at gmail.com
Tue May 29 20:08:10 PDT 2007



Ary Manzana wrote:
> Bill Baxter escribió:
>> Something like:
>>      public void Foo(T)(T p1)
>>      {
>>      }
>>
>>      public void Foo(T,dummy=float)(T p1, bool b)
>>      {
>>      }
>>
>> It's silly that you have to do that, but since that workaround is
>> available, I don't think Walter considers fixing it a very high priority.
> 
> !
> 
> This is so wrong. The language is trying to be elegant with "foreach",
> "delegate" and some other stuff, while there are holes in many other
> places, like this one.
> 
> I'm not saying that it's bad the problem exists. I think it's bad fixing
> this kind of things has low priority, while adding new features to the
> language has high priority. I know fixing is boring, and new stuff is
> fun. But... Workaround Oriented Programming is not fun. :-(

I'm pretty sure this hasn't been fixed not because it's boring, but
because it's hard.  As Jarret said, the original code expands to two
templates with exactly the same name and set of arguments.

I mean, would you call it a bug that you can't have two methods with the
same name and same arguments, but differ by their contents?  This isn't
so much a bug with D, but just a limitation.

I vaguely remember someone (possibly Walter) saying at some point that
fixing this would require changing the compiler to distinguish between
templates and templated functions; which would require duplicating a lot
of code, and making the front end a lot messier.  When there's a simple
(if ugly) workaround available, I don't see how this is more important
than getting good const semantics.

This you can work around.  Working around a lack of good const is much
harder :)

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/


More information about the Digitalmars-d-learn mailing list