www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to test for type without refs?

reply Charles Hixson via Digitalmars-d-learn writes:
I thought that in:
     T* user(T)()
     {    static assert (T.sizeof < bfHdr.user_.length);
           static assert (__traits(isPOD, T) );
           return    cast(T*) bfHdr.user_.ptr;
     }
the line:
static assert (__traits(isPOD, T) );

would test for there not being any embedded refs, pointers, etc., but
unittest
{
...
     struct    thead2    {    string    test;    }
     auto    userTest2    =    bf.user!(thead2)();
}
executes without complaint.  Is there a better way?
Mar 17 2015
parent reply "anonymous" <anonymous example.com> writes:
On Tuesday, 17 March 2015 at 14:06:19 UTC, Charles Hixson wrote:
 I thought that in:
     T* user(T)()
     {    static assert (T.sizeof < bfHdr.user_.length);
           static assert (__traits(isPOD, T) );
           return    cast(T*) bfHdr.user_.ptr;
     }
 the line:
 static assert (__traits(isPOD, T) );

 would test for there not being any embedded refs, pointers, 
 etc., but
 unittest
 {
 ...
     struct    thead2    {    string    test;    }
     auto    userTest2    =    bf.user!(thead2)();
 }
 executes without complaint.  Is there a better way?
There's std.traits.hasIndirections <http://dlang.org/phobos/std_traits.html#hasIndirections>.
Mar 17 2015
parent Charles Hixson via Digitalmars-d-learn writes:
On 03/17/2015 07:27 AM, anonymous via Digitalmars-d-learn wrote:
 On Tuesday, 17 March 2015 at 14:06:19 UTC, Charles Hixson wrote:
 I thought that in:
     T* user(T)()
     {    static assert (T.sizeof < bfHdr.user_.length);
           static assert (__traits(isPOD, T) );
           return    cast(T*) bfHdr.user_.ptr;
     }
 the line:
 static assert (__traits(isPOD, T) );

 would test for there not being any embedded refs, pointers, etc., but
 unittest
 {
 ...
     struct    thead2    {    string    test;    }
     auto    userTest2    =    bf.user!(thead2)();
 }
 executes without complaint.  Is there a better way?
There's std.traits.hasIndirections <http://dlang.org/phobos/std_traits.html#hasIndirections>.
Thanks. That did the job. (I was looking at ...dmd-doc/html/d/traits.html instead.)
Mar 17 2015