Advertisement
Siapran

generic vector definition

Mar 12th, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #ifndef VECTOR_GENERIC_MACROS
  2. #define VECTOR_GENERIC_MACROS
  3.  
  4.     #ifndef TOKENPASTE
  5.     #define TOKENPASTE(x, y) x ## y
  6.     #endif
  7.  
  8.     #define vector_at(vector, pos) (vector).data[pos]
  9.  
  10.     #define vector_init(T) TOKENPASTE(vector_init_, T)
  11.     #define vector_destroy(T) TOKENPASTE(vector_destroy_, T)
  12.     #define vector_push_back(T) TOKENPASTE(vector_push_back_, T)
  13.     #define vector_pop_back(T) TOKENPASTE(vector_pop_back_, T)
  14.     #define vector_resize(T) TOKENPASTE(vector_resize_, T)
  15.     #define vector_reserve(T) TOKENPASTE(vector_reserve_, T)
  16.  
  17.     #define vector_t(T) TOKENPASTE(vector_t_, T)
  18.  
  19. #endif
  20.  
  21. typedef struct
  22. {
  23.     size_t size;
  24.     size_t capacity;
  25.     TYPE *data;
  26. } vector_t(TYPE);
  27.  
  28.  
  29. void vector_init(TYPE)(vector_t(TYPE) *vector, size_t size);
  30. void vector_destroy(TYPE)(vector_t(TYPE) *vector);
  31.  
  32. void vector_push_back(TYPE)(vector_t(TYPE) *vector, TYPE value);
  33. TYPE vector_pop_back(TYPE)(vector_t(TYPE) *vector);
  34.  
  35. void vector_resize(TYPE)(vector_t(TYPE) *vector, size_t size);
  36. void vector_reserve(TYPE)(vector_t(TYPE) *vector, size_t size);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement