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::extensions::equality_operators< type_t, iequatable< type_t > > xtd::basic_array< value_type, allocator_t > xtd::basic_array< xtd::drawing::imaging::encoder_parameter, allocator_t > xtd::basic_array< xtd::byte, allocator_t > xtd::basic_array< byte, allocator_t > xtd::basic_array< xtd::uint16, allocator_t > xtd::collections::generic::key_value_pair< control_ref, horizontal_control_layout_style > xtd::collections::generic::key_value_pair< control_ref, vertical_control_layout_style > xtd::collections::generic::list< int32 > xtd::collections::generic::list< xtd::drawing::color > xtd::collections::generic::list< xtd::byte > xtd::collections::generic::list< byte > xtd::collections::generic::helpers::wrap_pointer_iterator< value_t, iterator_tag_t > xtd::enum_object< enum_t > xtd::read_only_span< type_t, extent > xtd::span< type_t, extent > xtd::text::basic_string_builder< char_t, traits_t, allocator_t >

Definition

template<class 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.hpp:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Examples
boxed_info.cpp, 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()


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