1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/ice14929.d(45): Error: cast(Node)(*this.current).items[this.index] is not an lvalue
5 fail_compilation/ice14929.d(88): Error: template instance ice14929.HashMap!(ulong, int).HashMap.opBinaryRight!"in" error instantiating
6 fail_compilation/ice14929.d(92):        instantiated from here: HashmapComponentStorage!int
7 fail_compilation/ice14929.d(92): Error: template instance ice14929.isComponentStorage!(HashmapComponentStorage!int, int) error instantiating
8 fail_compilation/ice14929.d(92):        while evaluating: `static assert(isComponentStorage!(HashmapComponentStorage!int, int))`
9 ---
10 */
11 
HashMap(K,V)12 struct HashMap(K, V)
13 {
14     V* opBinaryRight(string op)(K key) const if (op == "in")
15     {
16         size_t index;
17         foreach (ref node; buckets[index].range)
18         {
19             return &(node.value);
20         }
21         return null;
22     }
23 
24     struct Node
25     {
26         K key;
27         V value;
28     }
29 
30     alias Bucket = UnrolledList!(Node);
31     Bucket[] buckets;
32 }
33 
UnrolledList(T)34 struct UnrolledList(T)
35 {
36     Range range() const pure
37     {
38         return Range(_front);
39     }
40 
41     static struct Range
42     {
43         ref T front() const @property
44         {
45             return cast(T) current.items[index];
46         }
47         void popFront() pure
48         {
49         }
50         bool empty() const pure @property
51         {
52             return true;
53         }
54         const(Node)* current;
55         size_t index;
56     }
57 
58     Node* _front;
59 
60     static struct Node
61     {
62         ContainerStorageType!T[10] items;
63     }
64 }
65 
66 template ContainerStorageType(T)
67 {
68     alias ContainerStorageType = T;
69 }
70 
71 template isComponentStorage(CS, C)
72 {
73     enum bool isComponentStorage = is(typeof(
74     (inout int = 0)
75     {
76         CS cs = CS.init;
77         ulong eid;
78         cs.add(eid, c);
79     }));
80 }
81 
82 struct HashmapComponentStorage(ComponentType)
83 {
84     private HashMap!(ulong, ComponentType) components;
85 
86     void add(ulong eid, ComponentType component)
87     {
88         assert(eid !in components);
89     }
90 }
91 
92 static assert(isComponentStorage!(HashmapComponentStorage!int, int));
93 
94 void main()
95 {
96 }
97