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> struct hash<std::pair<T1, T2>>
35  {
36  using argument_type = std::pair<T1, T2>;
37  using result_type = std::size_t;
38  result_type operator()(argument_type const& s) const noexcept
39  {
40  result_type seed = 0;
41  boost::hash_combine(seed, std::hash<T1> {}(s.first));
42  boost::hash_combine(seed, std::hash<T2> {}(s.second));
43 
44  return seed;
45  }
46  };
47  template<class...Ts> struct hash<std::tuple<Ts...>>
48  {
49  public:
50  using argument_type = std::tuple<Ts...>;
51  using result_type = std::size_t;
52  private:
53  template <std::size_t N>
54  using type = typename std::tuple_element<N, argument_type>::type;
55 
56  template<class = std::make_index_sequence<sizeof...(Ts)>>
57  struct helper;
58 
59  template<std::size_t...Is>
60  struct helper<std::index_sequence<Is...>>
61  {
62  static result_type hash(argument_type const& s) noexcept
63  {
64  result_type seed = 0;
65  (boost::hash_combine(seed, std::hash<type<Is>> {}(std::get<Is>(s))), ...);
66  return seed;
67  }
68  };
69  public:
70  result_type operator()(argument_type const& s) const noexcept
71  {
72  return helper<>::hash(s);
73  }
74  };
75 }
std::hash< std::pair< T1, T2 > >::result_type
std::size_t result_type
Definition: hash.h:37
std::hash< std::tuple< Ts... > >::argument_type
std::tuple< Ts... > argument_type
Definition: hash.h:50
std::hash< std::tuple< Ts... > >::result_type
std::size_t result_type
Definition: hash.h:51
std::hash< std::pair< T1, T2 > >::argument_type
std::pair< T1, T2 > argument_type
Definition: hash.h:36
std::hash< std::pair< T1, T2 > >::operator()
result_type operator()(argument_type const &s) const noexcept
Definition: hash.h:38
std
Definition: Application.h:66
std::hash< std::tuple< Ts... > >::operator()
result_type operator()(argument_type const &s) const noexcept
Definition: hash.h:70
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33