Shows how to use xtd::iequatable interface.
#include <xtd/console>
#include <xtd/iclonable>
public:
explicit foo(int value) : value_ {value} {}
uptr<object> clone()
const override {
return new_uptr<foo>(value_);}
string to_string() const noexcept override {return string::format("{}", value_);}
private:
int value_ = 0;
};
auto main() -> int {
auto f1 = foo {42};
console::write_line(
"f1 {{type = {}, value = {}}}",
typeof_(f1), f1);
console::write_line(
"f2 {{type = {}, value = {}}}",
typeof_(f2), *f2);
auto f3 = as<foo>(
f1.clone());
console::write_line(
"f3 {{type = {}, value = {}}}",
typeof_(f3), *f3);
}
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition iclonable.hpp:21
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
#define typeof_
Used to obtain the type object of a specified type or object.
Definition typeof.hpp:45
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10