xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::equality_comparer< type_t > Class Template Reference
Inheritance diagram for xtd::collections::generic::equality_comparer< type_t >:
xtd::collections::generic::iequality_comparer< type_t > xtd::interface

Definition

template<typename type_t>
class xtd::collections::generic::equality_comparer< type_t >

Provides a base class for implementations of the xtd::collections::generic::iequality_comparer <type_t> generic interface.

Definition
template<typename type_t>
Provides a base class for implementations of the xtd::collections::generic::iequality_comparer <type_...
Definition equality_comparer.hpp:35
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Header
#include <xtd/collections/equality_comparer
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality for type type_t, and specify that this definition be used with a collection type that accepts the xtd::collections::generic::iequality_comparer <type_t> generic interface. In the xtd framework, constructors of the xtd::collections::generic::dictionary <key_t, value_t> generic collection type accept this interface.
A default implementation of this interface is provided by the xtd::collections::generic::equality_comparer::default_equality_comparer property of the xtd::collections::generic::equality_comparer <type_t> generic class. The xtd::string_comparer class implements xtd::collections::generic::iequality_comparer <type_t> of type xtd::string.
This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the xtd::collections::generic::icomparer <type_t> generic interface.
We recommend that you derive from the xtd::collections::generic::equality_comparer <type_t> class instead of implementing the xtd::collections::generic::iequality_comparer <type_t> interface, because the xtd::collections::generic::equality_comparer <type_t> class tests for equality using the xtd::iequatable::equals method instead of the xtd::object::equals method. This is consistent with the contains, index_of, last_index_of, and remove methods of the xtd::collections::generic::dictionary <key_t, value_t> class and other generic collections.

Public Static Properties

static equality_comparer default_equality_comparer ()
 Gets the default equality comparer for the type specified by the generic argument.
 

Public Methods

bool equals (const type_t &x, const type_t &y) const noexcept override
 Determines whether the specified objects are equal.
 
xtd::size get_hash_code (const type_t &obj) const noexcept override
 Returns a hash code for the specified object.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::collections::generic::iequality_comparer< type_t >

Member Function Documentation

◆ default_equality_comparer()

template<typename type_t >
static equality_comparer xtd::collections::generic::equality_comparer< type_t >::default_equality_comparer ( )
inlinestatic

Gets the default equality comparer for the type specified by the generic argument.

Returns
The default instance of the xtd::collections::generic::equality_comparer <type_t> class.

◆ equals()

template<typename type_t >
bool xtd::collections::generic::equality_comparer< type_t >::equals ( const type_t &  x,
const type_t &  y 
) const
inlineoverridevirtualnoexcept

Determines whether the specified objects are equal.

Parameters
xThe first object of type type_t to compare.
yThe seco,d object of type type_t to compare.
Returns
true if the specified objects are equal; otherwise, false.
Remarks
Implement this method to provide a customized equality comparison for type type_t.
Notes to Implementers
Implementations are required to ensure that if the xtd::collections::generic::iequality_comparer::equals method returns true for two objects x and y, then the value returned by the xtd::collections::generic::iequality_comparer::get_hash_code method for x must equal the value returned for y. The xtd::collections::generic::iequality_comparer::equals method is reflexive, symmetric, and transitive. That is, it returns true if used to compare an object with itself; true for two objects x and y if it is true for y and x; and true for two objects x and z if it is true for x and y and also true for y and z.

Implements xtd::collections::generic::iequality_comparer< type_t >.

◆ get_hash_code()

template<typename type_t >
xtd::size xtd::collections::generic::equality_comparer< type_t >::get_hash_code ( const type_t &  obj) const
inlineoverridevirtualnoexcept

Returns a hash code for the specified object.

Parameters
objThe xtd::object for which a hash code is to be returned.
Returns
A hash code for the specified object.
Remarks
Implement this method to provide a customized hash code for type type_t, corresponding to the customized equality comparison provided by the xtd::collections::generic::iequality_comparer::equals method.
Notes to Implementers
Implementations are required to ensure that if the xtd::collections::generic::iequality_comparer::equals method returns true for two objects x and y, then the value returned by the xtd::collections::generic::iequality_comparer::get_hash_code method for x must equal the value returned for y.

Implements xtd::collections::generic::iequality_comparer< type_t >.


The documentation for this class was generated from the following file: