Changeset 4ef8fb3 for src/examples/gc_no_raii/src/vector.h
- Timestamp:
- May 4, 2016, 10:45:18 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- eb4f201
- Parents:
- 8a74081
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/src/vector.h
r8a74081 r4ef8fb3 21 21 size_t size; 22 22 }; 23 // 24 // //------------------------------------------------------------------------------25 // //Initialization26 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))27 //void ctor(vector(T, allocator_t) *const this);28 // 29 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))30 //void dtor(vector(T, allocator_t) *const this);31 // 32 // //------------------------------------------------------------------------------33 // //Capacity34 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))35 //static inline bool empty(vector(T, allocator_t) *const this)36 //{37 //return this->size == 0;38 //}39 // 40 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))41 //static inline bool size(vector(T, allocator_t) *const this)42 //{43 //return this->size;44 //}45 // 46 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))47 //static inline void reserve(vector(T, allocator_t) *const this, size_t size)48 //{49 //realloc(&this->storage, this->size+1);50 //}51 // 52 // //------------------------------------------------------------------------------53 // //Element access54 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))55 //static inline T at(vector(T, allocator_t) *const this, size_t index)56 //{57 //return data(&this->storage)[index];58 //}59 // 60 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))61 //static inline T ?[?](vector(T, allocator_t) *const this, size_t index)62 //{63 //return data(&this->storage)[index];64 //}65 // 66 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))67 //static inline T front(vector(T, allocator_t) *const this)68 //{69 //return data(&this->storage)[0];70 //}71 // 72 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))73 //static inline T back(vector(T, allocator_t) *const this)74 //{75 //return data(&this->storage)[this->size - 1];76 //}77 // 78 // //------------------------------------------------------------------------------79 // //Modifiers80 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))81 //void push_back(vector(T, allocator_t) *const this, T value);82 // 83 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))84 //void pop_back(vector(T, allocator_t) *const this);85 // 86 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))87 //void clear(vector(T, allocator_t) *const this);88 // 89 // //------------------------------------------------------------------------------90 // //Iterators91 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))92 //static inline T* begin(vector(T, allocator_t) *const this)93 //{94 //return data(&this->storage);95 //}96 // 97 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))98 //static inline const T* cbegin(const vector(T, allocator_t) *const this)99 //{100 //return data(&this->storage);101 //}102 // 103 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))104 //static inline T* end(vector(T, allocator_t) *const this)105 //{106 //return data(&this->storage) + this->size;107 //}108 // 109 //forall(otype T, otype allocator_t | allocator_c(T, allocator_t))110 //static inline const T* cend(const vector(T, allocator_t) *const this)111 //{112 //return data(&this->storage) + this->size;113 //}114 // 115 // //------------------------------------------------------------------------------116 // //Allocator117 //forall(otype T)118 //struct heap_allocator119 //{120 //T* storage;121 //size_t capacity;122 //};123 // 124 //forall(otype T)125 //void ctor(heap_allocator(T) *const this);126 // 127 //forall(otype T)128 //void dtor(heap_allocator(T) *const this);129 // 130 //forall(otype T)131 //void realloc(heap_allocator(T) *const this, size_t size);132 // 133 //forall(otype T)134 //static inline T* data(heap_allocator(T) *const this)135 //{136 //return this->storage;137 //}23 24 //------------------------------------------------------------------------------ 25 //Initialization 26 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 27 void ctor(vector(T, allocator_t) *const this); 28 29 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 30 void dtor(vector(T, allocator_t) *const this); 31 32 //------------------------------------------------------------------------------ 33 //Capacity 34 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 35 static inline bool empty(vector(T, allocator_t) *const this) 36 { 37 return this->size == 0; 38 } 39 40 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 41 static inline bool size(vector(T, allocator_t) *const this) 42 { 43 return this->size; 44 } 45 46 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 47 static inline void reserve(vector(T, allocator_t) *const this, size_t size) 48 { 49 realloc(&this->storage, this->size+1); 50 } 51 52 //------------------------------------------------------------------------------ 53 //Element access 54 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 55 static inline T at(vector(T, allocator_t) *const this, size_t index) 56 { 57 return data(&this->storage)[index]; 58 } 59 60 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 61 static inline T ?[?](vector(T, allocator_t) *const this, size_t index) 62 { 63 return data(&this->storage)[index]; 64 } 65 66 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 67 static inline T front(vector(T, allocator_t) *const this) 68 { 69 return data(&this->storage)[0]; 70 } 71 72 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 73 static inline T back(vector(T, allocator_t) *const this) 74 { 75 return data(&this->storage)[this->size - 1]; 76 } 77 78 //------------------------------------------------------------------------------ 79 //Modifiers 80 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 81 void push_back(vector(T, allocator_t) *const this, T value); 82 83 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 84 void pop_back(vector(T, allocator_t) *const this); 85 86 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 87 void clear(vector(T, allocator_t) *const this); 88 89 //------------------------------------------------------------------------------ 90 //Iterators 91 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 92 static inline T* begin(vector(T, allocator_t) *const this) 93 { 94 return data(&this->storage); 95 } 96 97 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 98 static inline const T* cbegin(const vector(T, allocator_t) *const this) 99 { 100 return data(&this->storage); 101 } 102 103 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 104 static inline T* end(vector(T, allocator_t) *const this) 105 { 106 return data(&this->storage) + this->size; 107 } 108 109 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 110 static inline const T* cend(const vector(T, allocator_t) *const this) 111 { 112 return data(&this->storage) + this->size; 113 } 114 115 //------------------------------------------------------------------------------ 116 //Allocator 117 forall(otype T) 118 struct heap_allocator 119 { 120 T* storage; 121 size_t capacity; 122 }; 123 124 forall(otype T) 125 void ctor(heap_allocator(T) *const this); 126 127 forall(otype T) 128 void dtor(heap_allocator(T) *const this); 129 130 forall(otype T) 131 void realloc(heap_allocator(T) *const this, size_t size); 132 133 forall(otype T) 134 static inline T* data(heap_allocator(T) *const this) 135 { 136 return this->storage; 137 }
Note: See TracChangeset
for help on using the changeset viewer.