status of "isComplex" in traits ?? (we have isFloatingPoint, for example)
jmh530
john.michael.hall at gmail.com
Wed Aug 18 18:55:39 UTC 2021
On Wednesday, 18 August 2021 at 17:36:48 UTC, H. S. Teoh wrote:
> On Wed, Aug 18, 2021 at 05:22:31PM +0000, james.p.leblanc via
> Digitalmars-d wrote:
>> Dear All,
>>
>> We indeed have **"isFloatingPoint"**, and **"isIntegral"** in
>> std.traits.
>>
>> But, what is the status/thinking about having **"isComplex"**
>> included in std.traits (... or ... potentially std.complex ??).
>>
>> I ask because, there are recommendations that we should start
>> using Complex!double, Complex!float ... so perhaps this is a
>> good time for a formal home for "isComplex" ??
>
> There's no need, you could just write:
>
> static if (is(T == Complex!U, U)) {
> // You can refer to U here to get at the type Complex
> // was instantiated with.
> }
>
> This has the added benefit of unpacking the parameter U for you.
>
>
> T
The implementation that the OP referenced in mir-core works for
any struct or enum that has re/im fields with floating point
numbers (or something like that) with a fallback for built-in
ones. Functions that use mir-core's isComplex can accept phobos
complex numbers or other user-defined complex numbers (that
fulfill the requirement), including the deprecated built-in ones.
More information about the Digitalmars-d
mailing list