source: tests/zombies/gc_no_raii/bug-repro/push_back.h @ 06ecda9

Last change on this file since 06ecda9 was fd54fef, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//------------------------------------------------------------------------------
2//Declaration
3trait allocator_c(T, allocator_t) {
4        void ctor(allocator_t* const);
5        void dtor(allocator_t* const);
6        void realloc(allocator_t* const, size_t);
7        T* data(allocator_t* const);
8};
9
10forall(T, allocator_t | allocator_c(T, allocator_t))
11struct vector
12{
13        allocator_t storage;
14        size_t size;
15};
16
17//------------------------------------------------------------------------------
18//Initialization
19forall(T, allocator_t | allocator_c(T, allocator_t))
20void vector_ctor(vector(T, allocator_t) *const this);
21
22forall(T, allocator_t | allocator_c(T, allocator_t))
23void dtor(vector(T, allocator_t) *const this);
24
25//------------------------------------------------------------------------------
26//Allocator
27forall(T)
28struct heap_allocator
29{
30        T* storage;
31        size_t capacity;
32};
33
34forall(T)
35void ctor(heap_allocator(T) *const this);
36
37forall(T)
38void dtor(heap_allocator(T) *const this);
39
40forall(T)
41void realloc(heap_allocator(T) *const this, size_t size);
42
43forall(T)
44inline T* data(heap_allocator(T) *const this)
45{
46        return this->storage;
47}
48
49//------------------------------------------------------------------------------
50//Capacity
51forall(T, allocator_t | allocator_c(T, allocator_t))
52inline bool empty(vector(T, allocator_t) *const this)
53{
54        return this->size == 0;
55}
56
57forall(T, allocator_t | allocator_c(T, allocator_t))
58inline bool size(vector(T, allocator_t) *const this)
59{
60        return this->size;
61}
62
63forall(T, allocator_t | allocator_c(T, allocator_t))
64inline void reserve(vector(T, allocator_t) *const this, size_t size)
65{
66        realloc(&this->storage, this->size+1);
67}
68
69//------------------------------------------------------------------------------
70//Modifiers
71forall(T, allocator_t | allocator_c(T, allocator_t))
72void push_back(vector(T, allocator_t) *const this, T value);
Note: See TracBrowser for help on using the repository browser.