Mercurial > projects > dstress
view addon/template_10_traits.d @ 1623:04022926a4d5
Fix dstress.run.b.bug_cod1_2528_C as reported by Don Clugston
Quoting Don's words from Ticket #8:
Fails because it returns 3 instead of 0.
The DStress test case is incorrect. The arrray literal is an int, so
it's 4 bytes. Casting it to void[] should give a length of 4 -- and
that's exactly what it does. Should be "return x.length - 4;".
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Fri, 05 Nov 2010 10:10:51 -0300 |
parents | 9603ea1557fc |
children |
line wrap: on
line source
/* Thor - D Metaprogramming Library version zero (c) 2004-2005 Aleksey Bobnev Public Domain Thanks go to: Andrei Alexandrescu - for admirable book "Modern C++ Design" and Loki library Andy Friesen - for apropos library, which actually pioneered meta-programming in D */ /+module Thor.traits;+/ module addon.template_10_traits; private { /+import Thor.meta;+/ import addon.template_10_meta; } template IsArray(T) { static const bool IsArray = false; } template IsArray(T : T[]) { static const bool IsArray = true; } template IsPointer(T) { static const bool IsPointer = false; } template IsPointer(T : T*) { static const bool IsPointer = true; } template IsObject(T) { static const bool IsObject = false; } template IsObject(T : Object) { static const bool IsObject = true; } template ElementType(T : T[]) { alias T ElementType; } template ElementType(T) { alias T ElementType; } template PointeeType(T : T*) { alias T PointeeType; } template PointeeType(T) { alias T PointeeType; } // type traits template Traits(T) { // IsConvertableTo // can T be converted to X? template IsConvertableTo(X) { static bool IsConvertableTo = false; } template IsConvertableTo(X : T) { static bool IsConvertableTo = true; } alias IsArray!(T) isArray; alias IsPointer!(T) isPointer; alias IsObject!(T) isObject; alias SelectType!((isArray),ElementType!(T),SelectType!((isPointer),PointeeType!(T),T)) subType; } template Inherits(Base : Object, Child : Object) { const bool Inherits = Traits!(Base).IsConvertableTo!(Child) && !Traits!(Child).IsConvertableTo!(Base); }