3
3
// / - store integers by static type, retrieve by dynamic type
4
4
// / - Double Dispatch
5
5
// / - Triple Dispatch
6
+ // / Quick and dirty test.
6
7
// / </summary>
7
8
8
9
#include < iostream>
@@ -36,8 +37,7 @@ typedef TTDimK::TypeList<A0, A1, A2> ALIST;
36
37
typedef TTDimK::TypeList<B0, B1, B2, B3> BLIST;
37
38
typedef TTDimK::TypeList<C0, C1, C2, C3> CLIST;
38
39
39
- struct A0 {
40
-
40
+ struct A0 {
41
41
// tensor index of class, depends only typelist, need not change when inheritance changed!
42
42
virtual size_t TensorIdx () { return TTDimK::TLIdx<ALIST, A0>(); }
43
43
@@ -50,7 +50,7 @@ struct B0 {
50
50
static string StaticTypeName () { return " B0" ; }
51
51
};
52
52
struct C0 {
53
- virtual size_t TensorIdx () { return TTDimK::TLIdx<CLIST, C0>(); }
53
+ virtual size_t TensorIdxOther () { return TTDimK::TLIdx<CLIST, C0>(); }
54
54
static string StaticTypeName () { return " C0" ; }
55
55
};
56
56
@@ -68,10 +68,23 @@ CreateInherited(B0, B1, BLIST)
68
68
CreateInherited(B1, B2, BLIST)
69
69
CreateInherited(B2, B3, BLIST)
70
70
71
- CreateInherited(C0, C1, CLIST)
72
- CreateInherited(C1, C2, CLIST)
73
- CreateInherited(C2, C3, CLIST)
71
+ // ------------- with different indexer function ------------------------------
72
+ #define CreateInheritedOther (BASE, ACTUAL, LIST ) \
73
+ struct ACTUAL : public BASE { \
74
+ virtual size_t TensorIdxOther () { return TTDimK::TLIdx<LIST, ACTUAL>(); } \
75
+ static string StaticTypeName () { return #ACTUAL; } \
76
+ };
74
77
78
+ CreateInheritedOther (C0, C1, CLIST)
79
+ CreateInheritedOther(C1, C2, CLIST)
80
+ CreateInheritedOther(C2, C3, CLIST)
81
+
82
+ namespace TTDimK {
83
+ template <>
84
+ struct TensorIndexerTrait <C0*> {
85
+ static size_t GetIndex (C0* obj) { return obj->TensorIdxOther (); }
86
+ };
87
+ }
75
88
// --------------------------------------------- main entry
76
89
int main ()
77
90
{
0 commit comments