type dynamic = struct {
type base = struct {}
std::unique_ptr(base);
public:
dynamic(object) {
type derived = struct : base {
decltype(object).remove_reference() value;
// implement constructors & etc
}
base = std::dynamic_allocate(std::unique, derived, forward(object));
}
// etc
};
dynamic.on_change(
event = member_variable_access,
action = [&](name) {
base.public_functions.insert(
name := "__" + name, // reserved names
function := [&](this) {
if (decltype(this).has_public_variable(name))
return dynamic(this.name);
else
throw std::no_operation(...);
},
virtual := true
);
}
// Repeat for member function
);
This is, of course, somewhat simplified pseudo-code. I haven't gone anywhere near locking down the API of type. However, I hope that you can get the gist of it.
One language that can do dynamic types, static types, type inference, meta-programming? Now that's what I call generic.
No comments:
Post a Comment