HashFunctions.h 731 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef HASHFUNCTIONS_H
#define HASHFUNCTIONS_H

#include <QGeoCoordinate>
#include <functional>

#include <QmlObjectListModel.h>

namespace std {

template <> struct hash<QGeoCoordinate> {
  std::size_t operator()(const QGeoCoordinate &c) {
    hash<double> h;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
14
    return h(c.latitude()) ^ (h(c.longitude()) << 1) ^ (h(c.altitude()) << 2);
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  }
};

template <template <class> class Container, class EntryType>
struct hash<Container<EntryType>> {
  std::size_t operator()(const Container<EntryType> &list) {
    std::size_t value = 0;
    hash<EntryType> h;
    for (const auto it = std::begin(list); it != std::end(list); ++it) {
      value ^= h(*it);
    }

    return value;
  }
};
} // namespace std

#endif // HASHFUNCTIONS_H