Dylan Storey

Recovering academic, hacker, tinkerer, scientist.

InLine::CPP and std::sort

Inline CPP is awesome unfortunately it throws a fit when you try and import algorithm so you can’t sort vectors.

#This is problematic for obvious reasons.

Here’s a work arounds:

#include <vector>
#include <cstdlib>
#include <climits>

std::vector <int> container;

	std::qsort(&container[0], container.size(), sizeof(int), [](const void* a, const void* b)
        int arg1 = *static_cast<const int*>(a);
        int arg2 = *static_cast<const int*>(b);
        if(arg1 < arg2) return -1;
        if(arg1 > arg2) return 1;
        return 0;

blog comments powered by Disqus