dmd 1.057 and 2.041 release

Robert Clipsham robert at octarineparrot.com
Mon Mar 8 14:38:39 PST 2010


On 08/03/10 22:03, bearophile wrote:
>> 2) What's the best way to translate this to the new operator regime?
>>
>> T foo(T)(T s) if (__traits(hasMember, T, "opAdd")) {
>>      return s + s;
>> }
>
> I have not found a good solution yet. This solution looks buggy (also because fixed-sized arrays have a buggy .init):
-snip-
> T foo(T)(T s) if (__traits(compiles, {return T.init + T.init;})) {
>      return s + s; // line 14
> }

Untested, will the following do what you need?

----
T foo(T)(T s) if (__traits(compiles, {return s + s;})) {
      return s + s;
}
----

Seems like you may as well test if you can add what you're passed rather 
than the initial value for the type.


More information about the Digitalmars-d-announce mailing list