Cumbersome overloading of mixed-in functions
Kristian
kjkilpi at gmail.com
Sun Aug 20 03:53:54 PDT 2006
On Sun, 20 Aug 2006 11:40:24 +0300, Chris Nicholson-Sauls
<ibisbasenji at gmail.com> wrote:
> nobody wrote:
>> kris wrote:
>>
>>> Jarrett Billingsley wrote:
>>>
>>>> Say I want to add a bunch of (virtual) methods to a class. All these
>>>> methods do very similar things, just on different types. Hmm, sounds
>>>> like a job for a template.
>>>
>>>
>>> Better to do it all manually and save yourself the grief. Mixin should
>>> perhaps be removed from the language until such time that it works in
>>> a reasonable manner :(
>> Just a little while ago I posed a question to D.learn about
>> implementing all the permutations possible of RGB, HSL, RGBA and HSLA.
>> The numbers from that post:
>> 3! + 3! + 4! + 4! = 60 types
>> (3! + 3! + 4! + 4!)^2 = 3600 opAssigns
>> Certainly manually is not really an option here.
>
> Right now, in cases such as this, the best option seems to be writing a
> simple source generator to cough up the code into a file. Usually the
> time/energy spent writing the generator program is reasonably less than
> manually typing them all out.
>
> -- Chris Nicholson-Sauls
Hmm, why the mixin does not simply generate/add the code, which is then
compiled normally with the original code? Similarly like macros work in
C/C++. This way there would be no naming conficts with function overloads
as Jarrett described earlier, for instance. The compiler knows when it
compiles the mixin code so the corresponging error messages can be
generated, etc.
I would very much like to see mixins working properly. It would be a great
asset for D if there were a good code generator ability!
More information about the Digitalmars-d
mailing list