Changeset ed3f3bf4


Ignore:
Timestamp:
Jul 4, 2016, 1:09:01 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
3f97e68, 888ee76
Parents:
f48ed47
Message:

fixed some of the obvious mistakes in generic vector

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/vector

    rf48ed47 red3f3bf4  
    4040
    4141forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    42 static inline bool size(vector(T, allocator_t) *const this)
     42static inline size_t size(vector(T, allocator_t) *const this)
    4343{
    4444        return this->size;
  • src/tests/libcfa_vector.c

    rf48ed47 red3f3bf4  
    11#include <stdlib>
     2
     3extern "C" {
     4        #include <stdio.h>
     5}
    26
    37#include <containers/vector>
    48
     9#define assert(x) do {\
     10        if(!(x)) {\
     11                printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
     12                abort();\
     13        }}while(0 == 1)\
     14
    515int main(int argc, char const *argv[]) {
    6         vector(int) iv;
     16        vector(int, heap_allocator(int)) iv;
     17        ctor(&iv);
     18
     19        assert(empty(&iv));
     20        assert(size(&iv) == 0);
     21        printf("%d\n", size(&iv));
    722
    823        push_back(&iv, 1);
     24        printf("%d\n", size(&iv));
     25        assert(size(&iv) == 1);
    926        push_back(&iv, 2);
     27        printf("%d\n", size(&iv));
     28        assert(size(&iv) == 2);
    1029        push_back(&iv, 3);
     30        printf("%d\n", size(&iv));
     31        assert(size(&iv) == 3);
    1132
    1233        assert(!empty(&iv));
    1334        assert(size(&iv) == 3);
    14         assert(iv[0] == 1);
    1535        assert(at(&iv, 0) == 1);
    16         assert(iv[1] == 2);
     36        assert((&iv)[0] == 1);
    1737        assert(at(&iv, 1) == 2);
    18         assert(iv[2] == 3);
     38        assert((&iv)[1] == 2);
    1939        assert(at(&iv, 2) == 3);
     40        assert((&iv)[2] == 3);
    2041
    2142        clear(&iv);
Note: See TracChangeset for help on using the changeset viewer.