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

Shows how to use xtd::delegate class.

#include <xtd/console>
#include <xtd/delegate>
using namespace xtd;
void goodbye(const ustring& s) {
console::write_line("Goodbye {}", s);
}
class object {
public:
void hello(const ustring& s) {
console::write_line("Hello {}", s);
}
};
auto main()->int {
using example_function = delegate<void(const ustring&)>;
auto instance = ::object {};
auto str = ustring {"World"};
//equivanet to : example_function f = {std::bind(&::object::hello, &instance, std::placeholders::_1)};
auto f = example_function {instance, &::object::hello};
// equivalent to : instance.hello(str)
f(str);
f = goodbye;
// equivalent to : goodbye(str)
f(str);
return 0;
}
// This code produces the following output:
//
// Hello, World
// Goodbye, World
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
@ f
The F key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10