Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / include / xbt / utility.hpp
index 84c282e..c39cf85 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2019. The SimGrid Team.
+/* Copyright (c) 2016-2020. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -8,10 +8,28 @@
 #define XBT_UTILITY_HPP
 
 #include <tuple>
+#include <functional>
 
 namespace simgrid {
 namespace xbt {
 
+/** @brief A hash which works with more stuff
+ *
+ *  It can hash pairs: the standard hash currently doesn't include this.
+ */
+template <class X> class hash : public std::hash<X> {
+};
+
+template <class X, class Y> class hash<std::pair<X, Y>> {
+public:
+  std::size_t operator()(std::pair<X, Y> const& x) const
+  {
+    hash<X> h1;
+    hash<X> h2;
+    return h1(x.first) ^ h2(x.second);
+  }
+};
+
 /** @brief Comparator class for using with std::priority_queue or boost::heap.
  *
  * Compare two std::pair by their first element (of type double), and return true when the first is greater than the
@@ -57,10 +75,6 @@ template <class List, class Elem> inline void intrusive_erase(List& list, Elem&
  */
 template<class T, T... N>
 class integer_sequence {
-  static constexpr std::size_t size()
-  {
-    return std::tuple_size<decltype(std::make_tuple(N...))>::value;
-  }
 };
 
 namespace bits {