それCでできるよ

template ...

それCでもできるよ!

#define VECTOR_PROTOTYPE(type)                                          \
    typedef struct type##_vector_ {                                     \
        type * data;                                                    \
                                                                        \
        int size;                                                       \
        int index;                                                      \
    } * type##_vector_t;                                                \
                                                                        \
    type##_vector_t make_##type##_vector();                             \
    void type##_vector_expand(type##_vector_t vec);                     \
    void delete_##type##_vector(type##_vector_t vec);                   \
                                                                        \
    type type##_vector_get(type##_vector_t vec, int index);             \
    void type##_vector_set(type##_vector_t vec, int index, type value); \
    void type##_vector_add(type##_vector_t vec, type value);            \
    int type##_vector_length(type##_vector_t vec);

#define VECTOR_DEFINE(type)                                             \
    type##_vector_t make_##type##_vector(){                             \
        type##_vector_t ret;                                            \
        SAFE_MALLOC(ret, sizeof(struct type##_vector_));                \
        SAFE_CALLOC(ret->data, DEFAULT_VECTOR_SIZE, sizeof(type));      \
                                                                        \
        ret->size = DEFAULT_VECTOR_SIZE;                                \
        ret->index = 0;                                                 \
                                                                        \
        return ret;                                                     \
    }                                                                   \
    void vector_##type##_expand(type##_vector_t vec){                   \
        SAFE_REALLOC(vec->data, sizeof(type) * vec->size * 2);          \
        int i = vec->size;                                              \
        for(;i < vec->size * 2; i++){                                   \
            vec->data[i] = (type)0;                                     \
        }                                                               \
        vec->size *= 2;                                                 \
    }                                                                   \
    void delete_##type##_vector(type##_vector_t vec){                   \
        free(vec->data);                                                \
        free(vec);                                                      \
    }                                                                   \
                                                                        \
    type type##_vector_get(type##_vector_t vec, int index){             \
        if (index >= vec->size){                                        \
            return (type)0;                                             \
        }                                                               \
                                                                        \
        return vec->data[index];                                        \
    }                                                                   \
    void type##_vector_set(type##_vector_t vec, int index, type value){ \
        while (index >= vec->size){                                     \
            vector_##type##_expand(vec);                                \
        }                                                               \
                                                                        \
        vec->data[index] = value;                                       \
    }                                                                   \
    void type##_vector_add(type##_vector_t vec, type value){            \
        while(vec->index >= vec->size){                                 \
            vector_##type##_expand(vec);                                \
        }                                                               \
                                                                        \
        vec->data[vec->index++] = value;                                \
    }                                                                   \
    int type##_vector_length(type##_vector_t vec){                      \
        return vec->index;                                              \
    }

今は反省している