xtd 0.2.0
__polymorphic_hasher.hpp
Go to the documentation of this file.
1
4
5#pragma once
7#if !defined(__XTD_CORE_INTERNAL__)
8#error "Do not include this file: Internal use only"
9#endif
11
12#include "../object.hpp"
13#include "../ihashable.hpp"
14#include <functional>
15#include <type_traits>
16
18template<typename key_t, typename bool_t>
19struct __object_hasher__ {};
20
21template<typename key_t>
22struct __object_hasher__<key_t, std::true_type> {
23 xtd::size operator()(const key_t& key) const {return static_cast<const xtd::object&>(key).get_hash_code();}
24};
25
26template<typename key_t>
27struct __object_hasher__<key_t, std::false_type> {
28 xtd::size operator()(const key_t& key) const {return std::hash<key_t> {}(key);}
29};
30
31template<typename key_t, typename bool_t>
32struct __ihashable_hasher__ {};
33
34template<typename key_t>
35struct __ihashable_hasher__<key_t, std::true_type> {
36 xtd::size operator()(const key_t& key) const {return static_cast<const xtd::ihashable&>(key).get_hash_code();}
37};
38
39template<typename key_t>
40struct __ihashable_hasher__<key_t, std::false_type> {
41 xtd::size operator()(const key_t& key) const {return __object_hasher__<key_t, typename std::is_base_of<xtd::object, key_t>::type> {}(key);}
42};
43
44template<typename key_t, typename bool_t>
45struct __polymorphic_hasher__ {};
46
47template<typename key_t>
48struct __polymorphic_hasher__<key_t, std::true_type> {
49 xtd::size operator()(const key_t& key) const {return __ihashable_hasher__<key_t, typename std::is_base_of<xtd::ihashable, key_t>::type> {}(key);}
50};
51
52template<typename key_t>
53struct __polymorphic_hasher__<key_t, std::false_type> {
54 xtd::size operator()(const key_t& key) const {return std::hash<key_t> {}(key);}
55};
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition ihashable.hpp:21
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23