[phobos] std.complex: ready for Phobos?
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Apr 19 22:55:18 PDT 2010
On Mon, Apr 19, 2010 at 23:05, Andrei Alexandrescu <andrei at erdani.com>wrote:
> It's a good point. Replying to your other point, we need some traits to
> tell whether something is a built-in float. For those that look like a
> float, we should define isFloatingPointLike.
>
> Andrei
>
>
> On 04/19/2010 04:02 PM, Lars Tandle Kyllingstad wrote:
>
>> Another point is that if Complex!T is to support arbitrary FP types,
>> then the trigonometric functions in std.math must too.
>>
>
Hi,
sorry to interrupt on your conversation (if I can post on the Phobos list),
but Lars' comment on CT interfaces got me thinking: is it enough to test the
subjacent type with these templates ?
- some type defines some operators (definesOperators!(T, "+", "-", ...)
- some type can be used with some functions (acceptedBy!(T, "hypot", ...)
- some type can be cast to real.
they could be all easily done, I think.
Mostly, it seems to me your code would have a global constraint with struct
Complex(T) if (definesOperators!(T, /+ the whole paraphernalia+/)
And, just around abs and arg, testing if T is accepted by hypot and atan2
_or_ if it can by explicitly cast to a real.
Commenting out abs/arg is enough to get a Complex!BigInt to compile.
but assignment does not work:
Complex!BigInt c;
c = 23; // opAssign asks for a BigInt (R : T)
maybe you should ask for something that can be cast to T.
Complex opAssign(R)(R r) if (__traits(compiles, {T t; R r; t=r;} ))
{
re = r;
im = 0;
return this;
}
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100420/ad7f77e2/attachment.html>
More information about the phobos
mailing list