Need trait of isPod.
Lutger
lutger.blijdestijn at gmail.com
Tue Oct 9 14:38:58 PDT 2007
Aarti_pl wrote:
> Matti Niemenmaa pisze:
...
>> That misses structs, which are also POD.
>>
>
> It should be just enough to add additional condition:
>
> (...)
> || is( T == struct )
> (...)
>
> and also probably union and enum.
>
> More:
> http://digitalmars.com/d/expression.html (section: is expression)
>
>
> BR
> Marcin Kuszczak
> (aarti_pl)
Correct me if I'm wrong, but I thought POD requires members of a struct
be public and also POD.
Here is a version (quick hack) that takes these criteria into account
(D1.0 syntax):
template isAtomicType( T ) {
static if( is( T == bool )
|| is( T == char )
|| is( T == wchar )
|| is( T == dchar )
|| is( T == byte )
|| is( T == short )
|| is( T == int )
|| is( T == long )
|| is( T == ubyte )
|| is( T == ushort )
|| is( T == uint )
|| is( T == ulong )
|| is( T == float )
|| is( T == double )
|| is( T == real )
|| is( T == ifloat )
|| is( T == idouble )
|| is( T == ireal ) )
const isAtomicType = true;
else static if (is(T == struct))
{
static if (is (typeof(T.tupleof))) // test for private members
{
static if (T.tupleof.length == 0)
const isAtomicType = true;
else
const isAtomicType = areAtomicTypes!(typeof(T.tupleof));
}
else
const isAtomicType = false;
}
else
const isAtomicType = false;
}
// helper template
template areAtomicTypes(T...)
{
static if (T.length == 1)
const areAtomicTypes = isAtomicType!(T[0]);
else
const areAtomicTypes = isAtomicType!(T[0]) &&
areAtomicTypes!(T[1..$]);
}
More information about the Digitalmars-d
mailing list