Skip to content

Commit

Permalink
fix isNumeric and NumericTypeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 27, 2012
1 parent 9f98163 commit a16920f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions std/traits.d
Expand Up @@ -3700,7 +3700,7 @@ template NumericTypeOf(T)

unittest
{
foreach (T; TypeTuple!(IntegralTypeList, FloatingPointTypeList))
foreach (T; NumericTypeList)
foreach (Q; TypeQualifierList)
{
static assert( is(Q!T == NumericTypeOf!( Q!T )));
Expand Down Expand Up @@ -4065,12 +4065,24 @@ unittest
}

/**
Detect whether we can treat T as a built-in numeric type (integral or floating
Detect whether $(D T) is a built-in numeric type (integral or floating
point).
*/
template isNumeric(T)
{
enum bool isNumeric = is(NumericTypeOf!T);
enum bool isNumeric = is(NumericTypeOf!T) && !isAggregateType!T;
}

unittest
{
foreach (T; TypeTuple!(NumericTypeList))
{
foreach (Q; TypeQualifierList)
{
static assert( isNumeric!(Q!T));
static assert(!isNumeric!(SubTypeOf!(Q!T)));
}
}
}

/**
Expand Down

0 comments on commit a16920f

Please sign in to comment.