Kagome
Polkadot Runtime Engine in C++17
wrapper.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_COMMON_WRAPPER_HPP
7 #define KAGOME_CORE_COMMON_WRAPPER_HPP
8 
9 #include <memory>
10 #include <type_traits>
11 
12 #include <boost/operators.hpp>
13 
14 namespace kagome::common {
15 
23  template <typename T, typename Tag>
24  struct Wrapper {
25  explicit Wrapper(T &&t) : data_(std::forward<T>(t)) {}
26 
27  T unwrap() {
28  return data_;
29  }
30 
31  const T &unwrap() const {
32  return data_;
33  }
34 
36  return data_;
37  }
38 
39  bool operator==(const Wrapper<T, Tag> &other) const {
40  return data_ == other.data_;
41  }
42 
43  private:
44  T data_;
45  };
46 
47  template <typename T,
48  typename Tag,
49  typename = std::enable_if<std::is_arithmetic<T>::value>>
50  bool operator<(const Wrapper<T, Tag> &a, const Wrapper<T, Tag> &b) {
51  return a.unwrap() < b.unwrap();
52  }
53 
54 } // namespace kagome::common
55 
56 template <typename T, typename Tag>
57 struct std::hash<kagome::common::Wrapper<T, Tag>> {
59  return std::hash<T>()(w.unwrap());
60  }
61 };
62 
63 #endif // KAGOME_CORE_COMMON_WRAPPER_HPP
const T & unwrap() const
Definition: wrapper.hpp:31
STL namespace.
std::size_t operator()(const kagome::common::Wrapper< T, Tag > &w)
Definition: wrapper.hpp:58
Make strongly typed structures from different concepts of the equal types. E.g. block height and roun...
Definition: wrapper.hpp:24
bool operator==(const Wrapper< T, Tag > &other) const
Definition: wrapper.hpp:39