Shows how to use xtd::boxing methods.
#include <xtd/boxing>
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/day_of_week>
#include <xtd/typeof>
class foo {
public:
foo() = default;
foo(int value) : value_(value) {}
int value() const noexcept {return value_;}
bool operator ==(const foo& v) const noexcept {return value_ == v.value_;}
bool operator <(const foo& v) const noexcept {return value_ < v.value_;}
private:
int value_ = 0;
};
template<typename type_t>
string get_boxed_info(const type_t& value) {
auto boxed_value = boxing(value);
return string::format(
"[type = {}, boxed type = {}, value = {}]",
typeof_(value),
typeof_(boxed_value), boxed_value.to_string());
}
auto main() -> int {
console::write_line(get_boxed_info(42));
console::write_line(get_boxed_info(42.84));
console::write_line(get_boxed_info(true));
console::write_line(get_boxed_info(day_of_week::saturday));
console::write_line(get_boxed_info("A string"));
console::write_line(get_boxed_info(U"A u32 string"));
console::write_line(get_boxed_info(date_time::now()));
console::write_line(get_boxed_info(foo(42)));
}
#define typeof_
Used to obtain the type object of a specified type or object.
Definition typeof.h:45
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10