CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
get_hash_code.h
1
3#pragma once
4
5#include <system/object.h>
6#include <system/shared_ptr.h>
7#include <system/details/hash_function.h>
8
9#include <functional>
10#include <type_traits>
11#include <thread>
12
13namespace System {
14
19template<typename T>
20typename std::enable_if<std::is_scalar<T>::value, int>::type
21GetHashCode(const T& obj)
22{
23 return static_cast<int>(System::Details::Hash_Meiyan(reinterpret_cast<const char*>(&obj), sizeof(obj)));
24}
25
30template<typename T>
31typename std::enable_if<!std::is_scalar<T>::value && System::IsSmartPtr<T>::value, int>::type
32GetHashCode(const T& obj)
33{
34 return obj->GetHashCode();
35}
36
41template<typename T>
42typename std::enable_if<System::IsExceptionWrapper<T>::value, int>::type
43GetHashCode(const T& obj)
44{
45 return obj->GetHashCode();
46}
47
52template<typename T>
53typename std::enable_if<!std::is_scalar<T>::value && !System::IsSmartPtr<T>::value && !System::IsExceptionWrapper<T>::value, int>::type
54GetHashCode(const T& obj)
55{
56 return obj.GetHashCode();
57}
58
60template<>
61inline int
62GetHashCode(const std::thread::id& id)
63{
64 std::hash<std::thread::id> hash;
65 return ASPOSECPP_CHECKED_CAST(int, hash(id));
66}
67
68} // namespace System
Definition: db_command.h:9
std::enable_if< std::is_scalar< T >::value, int >::type GetHashCode(const T &obj)
Returns a hash code for the specified scalar value.
Definition: get_hash_code.h:21
A template predicate that determines if the specified type is a Exception class or its descendant.
Definition: object.h:405
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499