Commit 3b51dc29 authored by Tom Niget's avatar Tom Niget

Add dot C++ impl

parent e6678055
......@@ -21,4 +21,35 @@ public:
}
};
struct function {};
template <typename Func, typename Self>
struct boundmethod {
[[no_unique_address]] Func func;
Self self;
boundmethod(Func func, Self self) : func(func), self(self) {}
template <typename... Args>
auto operator()(Args &&... args) const {
return func(self, std::forward<Args>(args)...);
}
};
template <typename Obj, std::derived_from<function> Attr>
auto bind(Obj obj, Attr attr) {
return boundmethod(attr, obj);
}
template <typename Obj, typename Attr>
requires (! std::derived_from<Attr, function>)
auto bind(Obj, Attr attr) {
return attr;
}
#define dot(OBJ, NAME) [](auto && obj) -> auto { return bind(obj, obj.NAME); }(OBJ)
#define dotp(OBJ, NAME) [](auto && obj) -> auto { return bind(obj, obj->NAME); }(OBJ)
#endif // TYPON_BASEDEF_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment