xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
xtd.core
include
xtd
collections
generic
helpers
hasher.hpp
Go to the documentation of this file.
1
4
#pragma once
5
#include "
../iequality_comparer.hpp
"
6
#include "
../../../object.hpp
"
7
#include "
../../../ihashable.hpp
"
8
#include <type_traits>
9
11
namespace
xtd
{
13
namespace
collections
{
15
namespace
generic
{
17
namespace
helpers
{
39
template
<
typename
key_t>
40
struct
hasher
{
42
45
using
argument_type
= key_t;
47
using
result_type
=
xtd::usize
;
49
51
54
hasher
() noexcept = default;
57
explicit
hasher
(const
xtd
::
collections
::
generic
::
iequality_comparer
<key_t>& comparer) noexcept : comparer {
const_cast<
xtd::collections::generic::iequality_comparer<key_t>
*
>
(&comparer)} {}
59
61
hasher
(
const
hasher
&)
noexcept
=
default
;
62
hasher
(
hasher
&&) noexcept = default;
63
hasher
& operator=(const
hasher
&) noexcept = default;
64
hasher
& operator=(
hasher
&&) noexcept = default;
66
68
74
auto operator()(const
argument_type
& key) const noexcept ->
result_type
{
75
if
(comparer)
return
comparer->get_hash_code(key);
76
if
constexpr
(std::is_polymorphic_v<argument_type> && std::is_base_of_v<xtd::ihashable, argument_type>)
return
static_cast<
const
xtd::ihashable
&
>
(key).
get_hash_code
();
77
else
if
constexpr
(std::is_polymorphic_v<argument_type> && std::is_base_of_v<xtd::object, argument_type>)
return
static_cast<
const
xtd::object
&
>
(key).
get_hash_code
();
78
else
if
constexpr
(std::is_invocable_v<std::hash<argument_type>,
const
argument_type
&>)
return
std::hash<argument_type> {}(key);
79
else
return
std::hash<std::intptr_t> {}(
reinterpret_cast<
std::intptr_t
>
(&key));
80
}
81
82
83
private
:
84
xtd::collections::generic::iequality_comparer<key_t>
*
comparer
=
nullptr
;
85
};
86
}
87
}
88
}
89
}
xtd::collections::generic::iequality_comparer
Defines methods to support the comparison of objects for equality.
Definition
iequality_comparer.hpp:34
xtd::ihashable
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition
ihashable.hpp:21
xtd::ihashable::get_hash_code
virtual auto get_hash_code() const noexcept -> xtd::usize=0
Serves as a hash function for a particular type.
xtd::object
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition
object.hpp:45
xtd::object::get_hash_code
virtual auto get_hash_code() const noexcept -> xtd::usize
Serves as a hash function for a particular type.
iequality_comparer.hpp
Contains xtd::collections::generic::iequality_comparer <type_t> interface.
xtd::usize
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition
usize.hpp:22
ihashable.hpp
Contains xtd::ihashable interface.
xtd::collections::generic::helpers
The xtd::collections::generic::helpers namespace contains helpers for generic collections,...
Definition
allocator.hpp:14
xtd::collections::generic
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition
comparer.hpp:16
xtd::collections
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition
any_pair.hpp:10
xtd
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition
abstract_object.hpp:8
object.hpp
Contains xtd::object class.
xtd::collections::generic::helpers::comparer
Implements a function object for compare data.
Definition
comparer.hpp:32
xtd::collections::generic::helpers::hasher::argument_type
key_t argument_type
Represents the argument type.
Definition
hasher.hpp:45
xtd::collections::generic::helpers::hasher::hasher
hasher() noexcept=default
Initializes a new instance of the hasher.
xtd::collections::generic::helpers::hasher::result_type
xtd::usize result_type
Represents the result type.
Definition
hasher.hpp:47
Generated on
for xtd by
Gammasoft
. All rights reserved.