0.2.0
Loading...
Searching...
No Matches
Pair.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <cstddef>
17#include <utility>
18#include <functional>
19
20namespace std
21{
23template<class T1, class T2>
24struct hash<std::pair<T1, T2>>
25{
28 std::size_t operator()(const std::pair<T1, T2>& f) const
29 {
30 auto hash1 = std::hash<T1>{}(f.first);
31 auto hash2 = std::hash<T2>{}(f.second);
32
33 if (hash1 != hash2)
34 {
35 return hash1 ^ hash2 << 1;
36 }
37
38 // If hash1 == hash2, their XOR is zero.
39 return hash1;
40 }
41};
42} // namespace std
std::size_t operator()(const std::pair< T1, T2 > &f) const
Hash function for std::pair.
Definition Pair.hpp:28