File: sort_test_util.cc

package info (click to toggle)
libtoxcore 0.2.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,992 kB
  • sloc: ansic: 70,235; cpp: 14,770; sh: 1,576; python: 649; makefile: 255; perl: 39
file content (32 lines) | stat: -rw-r--r-- 815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "sort_test_util.hh"

#include <array>
#include <cstddef>

#include "sort.h"
#include "util.h"

namespace {
template <typename T, std::size_t N>
int cmp_uint_array(const std::array<T, N> &a, const std::array<T, N> &b)
{
    for (std::size_t i = 0; i < a.size(); ++i) {
        const int cmp = cmp_uint(a[i], b[i]);
        if (cmp != 0) {
            return cmp;
        }
    }
    return 0;
}
}

const Sort_Funcs Some_Type::funcs = sort_funcs<Some_Type>();

int my_type_cmp(const void *_Nonnull va, const void *_Nonnull vb)
{
    const auto *a = static_cast<const Some_Type *>(va);
    const auto *b = static_cast<const Some_Type *>(vb);
    return cmp_uint_array(a->compare_value, b->compare_value);
}

bool operator<(const Some_Type &a, const Some_Type &b) { return a.compare_value < b.compare_value; }