|
|
#pragma once
|
|
|
|
|
|
#include <cstddef>
|
|
|
#include <functional>
|
|
|
#include <utility>
|
|
|
|
|
|
namespace c10 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class ConcreteType, class UnderlyingType>
|
|
|
class IdWrapper {
|
|
|
public:
|
|
|
using underlying_type = UnderlyingType;
|
|
|
using concrete_type = ConcreteType;
|
|
|
|
|
|
protected:
|
|
|
constexpr explicit IdWrapper(underlying_type id) noexcept(
|
|
|
noexcept(underlying_type(std::declval<underlying_type>())))
|
|
|
: id_(id) {}
|
|
|
|
|
|
constexpr underlying_type underlyingId() const
|
|
|
noexcept(noexcept(underlying_type(std::declval<underlying_type>()))) {
|
|
|
return id_;
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
friend size_t hash_value(const concrete_type& v) {
|
|
|
return std::hash<underlying_type>()(v.id_);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
friend constexpr bool operator==(
|
|
|
const concrete_type& lhs,
|
|
|
const concrete_type& rhs) noexcept {
|
|
|
return lhs.id_ == rhs.id_;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
friend constexpr bool operator!=(
|
|
|
const concrete_type& lhs,
|
|
|
const concrete_type& rhs) noexcept {
|
|
|
return !(lhs == rhs);
|
|
|
}
|
|
|
|
|
|
underlying_type id_;
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
#define C10_DEFINE_HASH_FOR_IDWRAPPER(ClassName) \
|
|
|
namespace std { \
|
|
|
template <> \
|
|
|
struct hash<ClassName> { \
|
|
|
size_t operator()(ClassName x) const { \
|
|
|
return hash_value(x); \
|
|
|
} \
|
|
|
}; \
|
|
|
}
|
|
|
|