by glouwbug · 5y ago · 0 comments
It's functionally blackbox compatible with the STL for the major containers. Unless you're writing heap spaced firmware where C++ with an STL isn't available I recommend you just use modern day C++.
Unless, of course, you want blazing fast compile times!
#include <stdio.h>
#define P
#define T int
#include <vec.h>
int compare(int* a, int* b) { return *b < *a; }
int main(void)
{
vec(int) a = vec_init(int)();
vec_push_back(int)(&a, 9);
vec_push_back(int)(&a, 1);
vec_push_back(int)(&a, 8);
vec_push_back(int)(&a, 3);
vec_push_back(int)(&a, 4);
vec_sort(int)(&a, compare);
foreach(vec(int), &a, it)
printf("%d\n", *it.ref);
vec_free(int)(&a);
}
I really should finish that writeup some day.CTL
#define P
#define T int
#include <vec.h>
STL #include <vector>
template class std::vector<int>;
C++ with its STL is just dramatically slower at compiling it all. C loves to chew through its basic syntax and O(1) lookup since every symbol is essentially unique (take that C++ and your function overloading!)