Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ private template fqnType(T,
format("%s*", fqnType!(PointerTarget!T, qualifiers))
);
}
else static if (is(T : __vector(V[N]), V, size_t N))
{
enum fqnType = chain!(
format("__vector(%s[%s])", fqnType!(V, qualifiers), N)
);
}
else
// In case something is forgotten
static assert(0, "Unrecognized type " ~ T.stringof ~ ", can't convert to fully qualified string");
Expand Down Expand Up @@ -783,6 +789,12 @@ unittest
static assert(fqn!(typeof(dVarArg)) == "void(...)");
static assert(fqn!(typeof(dVarArg2)) == "void(int, ...)");
static assert(fqn!(typeof(typesafeVarArg)) == "void(int[] ...)");

// SIMD vector
static if (is(__vector(float[4])))
{
static assert(fqn!(__vector(float[4])) == "__vector(float[4])");
}
}
}

Expand Down Expand Up @@ -5270,8 +5282,25 @@ unittest
//static assert( isAssociativeArray!EAA);
}

/**
* Detect whether type $(D T) is a builtin type.
*/
enum bool isBuiltinType(T) = is(BuiltinTypeOf!T) && !isAggregateType!T;

/**
* Detect whether type $(D T) is a SIMD vector type.
*/
enum bool isSIMDVector(T) = is(T : __vector(V[N]), V, size_t N);

unittest
{
alias __vector(float[4]) SimdVec;
static assert(isSIMDVector!(__vector(float[4])));
static assert(isSIMDVector!SimdVec);
static assert(!isSIMDVector!uint);
static assert(!isSIMDVector!(float[4]));
}

/**
* Detect whether type $(D T) is a pointer.
*/
Expand Down Expand Up @@ -5929,9 +5958,11 @@ template Unsigned(T)
{
template Impl(T)
{
static if (isUnsigned!T)
static if (is(T : __vector(V[N]), V, size_t N))
alias Impl = __vector(Impl!V[N]);
else static if (isUnsigned!T)
alias Impl = T;
else static if (isSigned!T)
else static if (isSigned!T && !isFloatingPoint!T)
{
static if (is(T == byte )) alias Impl = ubyte;
static if (is(T == short)) alias Impl = ushort;
Expand All @@ -5954,6 +5985,13 @@ unittest
static assert(is(U1 == uint));
static assert(is(U2 == const(uint)));
static assert(is(U3 == immutable(uint)));
static if (is(__vector(int[4])) && is(__vector(uint[4])))
{
alias Unsigned!(__vector(int[4])) UV1;
alias Unsigned!(const(__vector(int[4]))) UV2;
static assert(is(UV1 == __vector(uint[4])));
static assert(is(UV2 == const(__vector(uint[4]))));
}
//struct S {}
//alias U2 = Unsigned!S;
//alias U3 = Unsigned!double;
Expand Down Expand Up @@ -6003,7 +6041,9 @@ template Signed(T)
{
template Impl(T)
{
static if (isSigned!T)
static if (is(T : __vector(V[N]), V, size_t N))
alias Impl = __vector(Impl!V[N]);
else static if (isSigned!T)
alias Impl = T;
else static if (isUnsigned!T)
{
Expand All @@ -6028,6 +6068,14 @@ unittest
static assert(is(S1 == int));
static assert(is(S2 == const(int)));
static assert(is(S3 == immutable(int)));
static assert(is(Signed!float == float));
static if (is(__vector(int[4])) && is(__vector(uint[4])))
{
alias Signed!(__vector(uint[4])) SV1;
alias Signed!(const(__vector(uint[4]))) SV2;
static assert(is(SV1 == __vector(int[4])));
static assert(is(SV2 == const(__vector(int[4]))));
}
}


Expand Down