Conditional Templates
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Jan 29 06:17:00 PST 2007
Jarrett Billingsley wrote:
> "Derek Parnell" <derek at nomail.afraid.org> wrote in message
> news:1p0qyzhxblvjj$.xbog5ahy31gi$.dlg at 40tude.net...
>> Help! The D documentation makes me seem such a fool.
>>
>> Here is what I want to do ...
>>
>> I want to create a template for a single class member method that behaves
>> differently depending on the type of the one parameter supplied to the
>> method. In other words, if the method is called with a integer type of
>> parameter, D should instantiate one form of the member method, and if the
>> parameter is a floating point data type, D should instantiate another form
>> of the member method, and finally if the parameter is a specific class, D
>> should instantiate yet another form of the member method.
>
> I'm probably missing something important, but can't this be done with normal
> function overloading?
All integer types in D can implicitly convert to floating-point types.
And he wants integer and float types to behave differently. In order to
solve this use overloading you'd have to introduce a separate overload
for every integer type to avoid ambiguous overloads. That's a lot of
overloads :p...
And it wouldn't even work for the 'cent' and 'ucent' types when they get
added (they're reserved keywords for 128-bit integer types).
More information about the Digitalmars-d-learn
mailing list