xtd 0.2.0
Loading...
Searching...
No Matches
iequatable.cpp

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();
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();
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();
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
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