- #36
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
- 14,983
- 28
A function object would work:Jeff Reid said:A pointer to function is required since the routine compares records given 2 pointers.
Code:
struct comparator
{
inline bool operator()(const unsigned char *a, const unsigned char *b) const
{
// compare somehow. We know they're 8 bytes each, so...
return std::lexicographical_compare(a, a + 8, b, b + 8);
// memcmp might be faster, though.
}
};
// ...
std::vector<const char*> array;
// ...
std::sort(array.begin(), array.end(), comparator());
Last edited: