hash.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Raphael Grimm (raphael dot grimm at kit dot edu)
20 * @date 2019
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
27 #include <functional>
28 #include <tuple>
29 
30 #include <boost/functional/hash.hpp>
31 
32 namespace std
33 {
34  template <class T1, class T2>
35  struct hash<std::pair<T1, T2>>
36  {
37  using argument_type = std::pair<T1, T2>;
38  using result_type = std::size_t;
39 
41  operator()(argument_type const& s) const noexcept
42  {
43  result_type seed = 0;
44  boost::hash_combine(seed, std::hash<T1>{}(s.first));
45  boost::hash_combine(seed, std::hash<T2>{}(s.second));
46 
47  return seed;
48  }
49  };
50 
51  template <class... Ts>
52  struct hash<std::tuple<Ts...>>
53  {
54  public:
55  using argument_type = std::tuple<Ts...>;
56  using result_type = std::size_t;
57 
58  private:
59  template <std::size_t N>
60  using type = typename std::tuple_element<N, argument_type>::type;
61 
62  template <class = std::make_index_sequence<sizeof...(Ts)>>
63  struct helper;
64 
65  template <std::size_t... Is>
66  struct helper<std::index_sequence<Is...>>
67  {
68  static result_type
69  hash(argument_type const& s) noexcept
70  {
71  result_type seed = 0;
72  (boost::hash_combine(seed, std::hash<type<Is>>{}(std::get<Is>(s))), ...);
73  return seed;
74  }
75  };
76 
77  public:
78  result_type
79  operator()(argument_type const& s) const noexcept
80  {
81  return helper<>::hash(s);
82  }
83  };
84 } // namespace std
std::hash< std::pair< T1, T2 > >::result_type
std::size_t result_type
Definition: hash.h:38
std::hash< std::tuple< Ts... > >::argument_type
std::tuple< Ts... > argument_type
Definition: hash.h:55
std::hash< std::tuple< Ts... > >::result_type
std::size_t result_type
Definition: hash.h:56
std::hash< std::pair< T1, T2 > >::argument_type
std::pair< T1, T2 > argument_type
Definition: hash.h:37
std::hash< std::pair< T1, T2 > >::operator()
result_type operator()(argument_type const &s) const noexcept
Definition: hash.h:41
std
Definition: Application.h:66
std::hash< std::tuple< Ts... > >::operator()
result_type operator()(argument_type const &s) const noexcept
Definition: hash.h:79
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33