Mercurial > projects > dstress
changeset 223:9603ea1557fc
template specialization bug
Aleksey Bobnev <uw@front.ru>
2004-12-27
news:cqp4fk$1dcj$1@digitaldaemon.com
nntp://digitalmars.com/digitalmars.D.bugs/2613
author | thomask |
---|---|
date | Sat, 01 Jan 2005 04:47:14 +0000 |
parents | a0f0b23919a6 |
children | 7d62be503e5f |
files | addon/template_10_meta.d addon/template_10_traits.d addon/template_10_typelist.d reporter.txt run/template_10.d run/template_11.d run/template_12.d |
diffstat | 7 files changed, 594 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addon/template_10_meta.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,47 @@ +/* + 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.meta;+/ +module addon.template_10_meta; + +class NullT +{ +} + +template Equal(T0,T1) +{ + const bool Equal = false; +} + +template Equal(T0,T1 : T0) +{ + const bool Equal = true; +} + +template SelectType(bool c, T0,T1) +{ + alias T0 SelectType; +} + +template SelectType(bool c : false, T0,T1) +{ + alias T1 SelectType; +} + +template SelectAlias(bool c, alias T0,alias T1) +{ + alias T0 SelectAlias; +} + +template SelectAlias(bool c : false, alias T0, alias T1) +{ + alias T1 SelectAlias; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addon/template_10_traits.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,97 @@ +/* + 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); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addon/template_10_typelist.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,389 @@ +/* + 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.typelist;+/ +module addon.template_10_typelist; + +private +{ + /+import Thor.meta;+/ + import addon.template_10_meta; +} + + +class TypeList +{ + alias NullT H; + alias NullT T; + template Length() + { + static const int Length = 0; + } +} + +template Length(_TL : TypeList) +{ + static const int Length = 1 + .Length!(_TL.T); +} + +template Length(_TL : NullT) +{ + static const int Length = 0; +} + + +template RemoveAll(_TL : TypeList, T) +{ + alias SelectType!(Equal!(_TL.H,T),.RemoveAll!(_TL.T,T), + .Cons!(_TL.H,.RemoveAll!(_TL.T,T)) + ) RemoveAll; +} + +template RemoveAll(_TL : NullT, T) +{ + alias NullT RemoveAll; +} + +template RemoveAll(_TL, T : NullT) +{ + alias _TL RemoveAll; +} + +template TypeidPrint(_TL : TypeList) +{ + void TypeidPrint() + { + typeid(_TL.H).print(); + .TypeidPrint!(_TL.T)(); + } +} + +template TypeidPrint(_T) +{ + void TypeidPrint() + { + typeid(_T).print(); + } +} + +template TypeidPrint(_TL : NullT) +{ + void TypeidPrint() + { + } +} + +/* + Construct type list from head and tail + typical use : + Cons!(A,Cons!(B,Cons!(C,NullT))) +*/ +template Cons(_Head, _Tail : TypeList) +{ + class Cons : TypeList + { + alias _Head H; + alias _Tail T; + template Length() + { + static const int Length = 1 + .Length!(T); + } + } +} + +template Cons(_Head : NullT, _Tail : TypeList) +{ + class Cons : TypeList + { + alias _Tail.H H; + alias _Tail.T T; + template Length() + { + static const int Length = .Length!(_Tail); + } + } +} + +template Cons(_Head, _Tail : NullT) +{ + class Cons : TypeList + { + alias _Head H; + alias _Tail T; + template Length() + { + static const int Length = 1; + } + } +} + +template TL(T0) +{ + class TL : TypeList + { + public: + alias T0 H; + alias NullT T; + template Length() + { + static const int Length = 1; + } + } +} + +// auto-generated up to 20 parameters +template TL(T0,T1) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1) T; + template Length() + { + static const int Length = 2; + } + } +} +template TL(T0,T1,T2) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2) T; + template Length() + { + static const int Length = 3; + } + } +} +template TL(T0,T1,T2,T3) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3) T; + template Length() + { + static const int Length = 4; + } + } +} +template TL(T0,T1,T2,T3,T4) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4) T; + template Length() + { + static const int Length = 5; + } + } +} +template TL(T0,T1,T2,T3,T4,T5) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5) T; + template Length() + { + static const int Length = 6; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6) T; + template Length() + { + static const int Length = 7; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7) T; + template Length() + { + static const int Length = 8; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8) T; + template Length() + { + static const int Length = 9; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9) T; + template Length() + { + static const int Length = 10; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10) T; + template Length() + { + static const int Length = 11; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11) T; + template Length() + { + static const int Length = 12; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12) T; + template Length() + { + static const int Length = 13; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13) T; + template Length() + { + static const int Length = 14; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) T; + template Length() + { + static const int Length = 15; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15) T; + template Length() + { + static const int Length = 16; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16) T; + template Length() + { + static const int Length = 17; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17) T; + template Length() + { + static const int Length = 18; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18) T; + template Length() + { + static const int Length = 19; + } + } +} +template TL(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19) +{ + class TL : TypeList + { + public: + alias T0 H; + alias .TL!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19) T; + template Length() + { + static const int Length = 20; + } + } +} \ No newline at end of file
--- a/reporter.txt Thu Dec 30 11:05:29 2004 +0000 +++ b/reporter.txt Sat Jan 01 04:47:14 2005 +0000 @@ -1,6 +1,6 @@ Thanks to all the bug reporters and for the test case suggestions. - +Aleksey Bobnev <uw@front.ru> Andy Friesen <andy@ikagames.com> Ant <duitoolkit@yahoo.ca> Arcane Jill <Arcane_member@pathlink.com>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/template_10.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,21 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ Aleksey Bobnev <uw@front.ru> +// @date@ 2004-12-27 +// @uri@ news:cqp4fk$1dcj$1@digitaldaemon.com +// @url@ nntp://digitalmars.com/digitalmars.D.bugs/2613 + +module dstress.run.template_10; + +import addon.template_10_typelist; + +template IsArray(T) { static const bool IsArray = false; } +template IsArray(T : T[]) { static const bool IsArray = true; } + +int main(){ + assert(IsArray!(int[])==1); + assert(IsArray!(int)==0); + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/template_11.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,19 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ Aleksey Bobnev <uw@front.ru> +// @date@ 2004-12-27 +// @uri@ news:cqp4fk$1dcj$1@digitaldaemon.com +// @url@ nntp://digitalmars.com/digitalmars.D.bugs/2613 + +module dstress.run.template_11; + +template IsArray(T) { static const bool IsArray = false; } +template IsArray(T : T[]) { static const bool IsArray = true; } + +int main(){ + assert(IsArray!(int[])==1); + assert(IsArray!(int)==0); + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/template_12.d Sat Jan 01 04:47:14 2005 +0000 @@ -0,0 +1,20 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ Aleksey Bobnev <uw@front.ru> +// @date@ 2004-12-27 +// @uri@ news:cqp4fk$1dcj$1@digitaldaemon.com +// @url@ nntp://digitalmars.com/digitalmars.D.bugs/2613 + +module dstress.run.template_12; + +import addon.template_10_traits; + +int main(){ + assert(IsArray!(int[])==1); + assert(IsArray!(int)==0); + assert(Traits!(int[]).isArray==1); + assert(Traits!(int).isArray==0); + return 0; +}