xtd 0.2.0
Loading...
Searching...
No Matches
xtd::iequatable< type_t > Class Template Referenceabstract
Inheritance diagram for xtd::iequatable< type_t >:
xtd::interface xtd::equality_operators< type_t, iequatable< type_t > > xtd::delegate< result_t(arguments_t...)>< value_t > xtd::basic_array< type_t, allocator_t > xtd::collections::generic::list< type_t, allocator_t > xtd::enum_object< enum_t > xtd::text::basic_string_builder< char_t, traits_t, allocator_t >

Definition

template<typename type_t>
class xtd::iequatable< type_t >

Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.

Namespace
xtd
Library
xtd.core
Remarks
This interface is implemented by types whose values can be equated (for example, the numeric and string classes). A value type or class implements the equals method to create a type-specific method suitable for determining equality of instances.
The xtd::icomparable<type_t> interface defines the compare_to method, which determines the sort order of instances of the implementing type. The iequatable<T> interface defines the equals method, which determines the equality of instances of the implementing type.
Examples
The following example shows how to use xtd::iequatable interface.
#include <xtd/console>
#include <xtd/iequatable>
using namespace xtd;
class foo : public iequatable<foo> {
public:
explicit foo(int value) : value_ {value} {}
bool equals(const foo& value) const noexcept override {return value_ == value.value_;}
private:
int value_ = 0;
};
auto main() -> int {
console::write_line("foo {{42}}.equals(foo {{42}}) = {}", foo {42}.equals(foo {42}));
console::write_line("foo {{42}}.equals(foo {{84}}) = {}", foo {42}.equals(foo {84}));
console::write_line("!foo {{42}}.equals(foo {{42}}) = {}", !foo {42}.equals(foo {42}));
console::write_line("!foo {{42}}.equals(foo {{84}}) = {}", !foo {42}.equals(foo {84}));
console::write_line("foo {{42}} == foo {{42}} = {}", foo {42} == foo {42});
console::write_line("foo {{42}} == foo {{84}} = {}", foo {42} == foo {84});
console::write_line("foo {{42}} != foo {{42}} = {}", foo {42} != foo {42});
console::write_line("foo {{42}} != foo {{84}} = {}", foo {42} != foo {84});
}
// This code produces the following output :
//
// foo {42}.equals(foo {42}) = true
// foo {42}.equals(foo {84}) = false
// !foo {42}.equals(foo {42}) = false
// !foo {42}.equals(foo {84}) = true
// foo {42} == foo {42} = true
// foo {42} == foo {84} = false
// foo {42} != foo {42} = false
// foo {42} != foo {84} = true
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
generic_icollection.cpp, generic_ienumerable2.cpp, generic_ienumerator.cpp, generic_ilist.cpp, generic_list.cpp, generic_list4.cpp, hash_code.cpp, ienumerable.cpp, ienumerator.cpp, iequatable.cpp, object_and_iequatable.cpp, and sprintf_class.cpp.

Public Methods

virtual bool equals (const type_t &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 

Member Function Documentation

◆ equals()

template<typename type_t >
virtual bool xtd::iequatable< type_t >::equals ( const type_t &  ) const
pure virtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implemented in xtd::any_object, xtd::box< type_t >, xtd::console_key_info, xtd::date_time, xtd::guid, xtd::time_span, xtd::time_zone_info, xtd::toolkit, xtd::type_object, xtd::version, and xtd::uri.


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