#include <xtd/xtd>
public:
explicit user(int id, const string& name) : id_ {id}, name_ {name} {}
int id() const noexcept {return id_;}
const string& name() const noexcept {return name_;}
bool equals(const object& other) const noexcept override {return is<user>(other) && equals(as<user>(other));}
bool equals(const user& other) const noexcept override {return id_ == other.id_ && name_ == other.name_;}
size_t get_hash_code() const noexcept override {return hash_code::combine(id_, name_);}
string to_string() const noexcept override {return string::format("user: id = {}, name = {}", id_, name_);}
private:
int id_ = 0;
string name_;
};
auto main() -> int {
auto user1 = user {1, "Example"};
auto user2 =
user {1,
"Example"};
auto user3 =
user {2,
"Different"};
console::write_line("user1 equals user2: {}", user1.equals(user2));
console::write_line("user1 equals user3: {}", user1.equals(user3));
console::write_line("user1 equals user2 (object): {}", user1.equals(as<object>(user2)));
console::write_line("user1 equals user3 (object): {}", user1.equals(as<object>(user3)));
console::write_line("user1 hash code: {}", user1.get_hash_code());
console::write_line("user2 hash code: {}", user2.get_hash_code());
console::write_line("user3 hash code: {}", user3.get_hash_code());
console::write_line("user1 == user2: {}", user1 == user2);
console::write_line("user1 != user3: {}", user1 != user3);
console::write_line(user1.to_string());
console::write_line(user2.to_string());
console::write_line(user3.to_string());
}
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
@ user
The environment variable is stored or retrieved from the HKEY_CURRENT_USER\Environment key in the Win...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10