digitalmars.D - Need trait of isPod.
- Yang Bo (1/1) Oct 09 2007 Because I really want to know whether a type is pod.
- Aarti_pl (29/30) Oct 09 2007 Simple template should be just enough.
- Matti Niemenmaa (4/35) Oct 09 2007 That misses structs, which are also POD.
- Aarti_pl (11/45) Oct 09 2007 It should be just enough to add additional condition:
- Paolo Invernizzi (4/56) Oct 08 2007 Not related... but what's the expression for testing an associative
- Marcin Kuszczak (16/20) Oct 09 2007 I found following template in Tango core/Traits.d:
- Paolo Invernizzi (8/36) Oct 10 2007 This static assert is false under GDC 0.24...
- Frits van Bommel (14/21) Oct 10 2007 The closing bracket of the first typeof() is misplaced. The correct code...
- Aarti_pl (8/11) Oct 10 2007 Just for clarification: That's not my code. It's taken from Tango as I
- Lutger (50/69) Oct 09 2007 Correct me if I'm wrong, but I thought POD requires members of a struct
- Janice Caron (2/3) Oct 09 2007 So are fixed-size arrays of PODs.
Because I really want to know whether a type is pod.
Oct 09 2007
Yang Bo pisze:Because I really want to know whether a type is pod.Simple template should be just enough. See: http://dsource.org/projects/tango/browser/trunk/tango/core/Variant.d 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 const isAtomicType = false; } BR Marcin Kuszczak (aarti_pl)
Oct 09 2007
Aarti_pl wrote:Yang Bo pisze:That misses structs, which are also POD. -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fiBecause I really want to know whether a type is pod.Simple template should be just enough. See: http://dsource.org/projects/tango/browser/trunk/tango/core/Variant.d 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 const isAtomicType = false; }
Oct 09 2007
Matti Niemenmaa pisze:Aarti_pl wrote: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)Yang Bo pisze:That misses structs, which are also POD.Because I really want to know whether a type is pod.Simple template should be just enough. See: http://dsource.org/projects/tango/browser/trunk/tango/core/Variant.d 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 const isAtomicType = false; }
Oct 09 2007
Not related... but what's the expression for testing an associative array? DMD 1.0 please... Paolo Aarti_pl wrote:Matti Niemenmaa pisze:Aarti_pl wrote: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)Yang Bo pisze:That misses structs, which are also POD.Because I really want to know whether a type is pod.Simple template should be just enough. See: http://dsource.org/projects/tango/browser/trunk/tango/core/Variant.d 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 const isAtomicType = false; }
Oct 08 2007
Paolo Invernizzi wrote:Not related... but what's the expression for testing an associative array? DMD 1.0 please... PaoloI found following template in Tango core/Traits.d: private template isAssocArrayType( T ) { const bool isAssocArrayType = is( typeof(T.init.values[0] [typeof(T.init.keys[0])] == T ); } I don't know if it really works (why is there private access qualifier???). Probably better answer could give Tango people... and tests of course :-) -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why... I believe in Jesus - http://www.zapytajmnie.com (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ -------------------------------------
Oct 09 2007
This static assert is false under GDC 0.24... template isAssocArrayType( T ) { const bool isAssocArrayType = is( typeof(T.init.values[0][typeof(T.init.keys[0])]) == T ); } static assert( isAssocArrayType!( int[char[]] ) ); Paolo Marcin Kuszczak Wrote:Paolo Invernizzi wrote:Not related... but what's the expression for testing an associative array? DMD 1.0 please... PaoloI found following template in Tango core/Traits.d: private template isAssocArrayType( T ) { const bool isAssocArrayType = is( typeof(T.init.values[0] [typeof(T.init.keys[0])] == T ); } I don't know if it really works (why is there private access qualifier???). Probably better answer could give Tango people... and tests of course :-) -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why... I believe in Jesus - http://www.zapytajmnie.com (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ -------------------------------------
Oct 10 2007
Paolo Invernizzi wrote:This static assert is false under GDC 0.24... template isAssocArrayType( T ) { const bool isAssocArrayType = is( typeof(T.init.values[0][typeof(T.init.keys[0])]) == T ); } static assert( isAssocArrayType!( int[char[]] ) );The closing bracket of the first typeof() is misplaced. The correct code is --- template isAssocArrayType( T ) { const bool isAssocArrayType = is( typeof(T.init.values[0])[typeof(T.init.keys[0])] == T ); } static assert( isAssocArrayType!( int[char[]] ) ); --- Which also seems to be how it appears in Tango. Maybe Marcin typed it over from Tango with a typo? (since the file hasn't changed for 7 months according to the svn repository, a copy-paste from an older buggier version seems unlikely)
Oct 10 2007
Frits van Bommel pisze: > Which also seems to be how it appears in Tango. Maybe Marcin typed itover from Tango with a typo? (since the file hasn't changed for 7 months according to the svn repository, a copy-paste from an older buggier version seems unlikely)Just for clarification: That's not my code. It's taken from Tango as I pointed out in my first post. I copied it from dsource page, so during stripping line numbers I probably lost one closing bracket. BR Marcin Kuszczak
Oct 10 2007
Aarti_pl wrote:Matti Niemenmaa pisze:...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..$]); }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)
Oct 09 2007
On 10/9/07, Matti Niemenmaa <see_signature for.real.address> wrote:That misses structs, which are also POD.So are fixed-size arrays of PODs.
Oct 09 2007