digitalmars.D - [std.traits] Detect complex numbers
- Luc Bourhis (24/24) Jan 14 2015 There is "isFloatingPointType!T" to find out whether type T is
- Luc Bourhis (2/2) Jan 14 2015 I forgot to mention the obvious: I simply parroted the code in
- John Colvin (4/28) Jan 14 2015 It doesn't answer your question as such, but you should take a
- Luc Bourhis (2/5) Jan 14 2015 The planned obsolescence of cdouble and consort is another issue
There is "isFloatingPointType!T" to find out whether type T is
one of the floating point types but I could not find anything
equivalent for complex numbers (cdouble, cfloat, creal) in Phobos
2.066 (which I installed with MacPorts for the record). Am I
missing something?
My goal was to detect types suitable as scalars in a linear
algebra context. I had to do it by hand:
enum bool supportedScalar(T) = is(ScalarTypeOf!T) &&
!isAggregateType!T;
private {
alias ScalarTypeList = TypeTuple!(float, double, real,
cfloat, cdouble, creal);
template ScalarTypeOf(T) {
static if (is(AliasThisTypeOf!T AT) && !is(AT[] == AT))
alias X = ScalarTypeOf!AT;
else
alias X = OriginalType!T;
static if (staticIndexOf!(Unqual!X, ScalarTypeList) >= 0)
alias ScalarTypeOf = X;
else
static assert(0, T.stringof~" is not a floating point
type");
}
}
Jan 14 2015
I forgot to mention the obvious: I simply parroted the code in std.traits!
Jan 14 2015
On Wednesday, 14 January 2015 at 13:38:05 UTC, Luc Bourhis wrote:
There is "isFloatingPointType!T" to find out whether type T is
one of the floating point types but I could not find anything
equivalent for complex numbers (cdouble, cfloat, creal) in
Phobos 2.066 (which I installed with MacPorts for the record).
Am I missing something?
My goal was to detect types suitable as scalars in a linear
algebra context. I had to do it by hand:
enum bool supportedScalar(T) = is(ScalarTypeOf!T) &&
!isAggregateType!T;
private {
alias ScalarTypeList = TypeTuple!(float, double, real,
cfloat, cdouble, creal);
template ScalarTypeOf(T) {
static if (is(AliasThisTypeOf!T AT) && !is(AT[] == AT))
alias X = ScalarTypeOf!AT;
else
alias X = OriginalType!T;
static if (staticIndexOf!(Unqual!X, ScalarTypeList) >= 0)
alias ScalarTypeOf = X;
else
static assert(0, T.stringof~" is not a floating point
type");
}
}
It doesn't answer your question as such, but you should take a
look at:
http://dlang.org/phobos/std_complex.html
Jan 14 2015
It doesn't answer your question as such, but you should take a look at: http://dlang.org/phobos/std_complex.htmlThe planned obsolescence of cdouble and consort is another issue I wanted to raise actually but better do it in a dedicated thread.
Jan 14 2015









"Luc Bourhis" <ljbo nowhere.com> 