generated from jbcoe/value_types
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
struct interfaceA {
void * object;
struct vtable_t {
std::string_view (*name)(const void *);
int (*count)(void *);
};
const vtable_t * vtable_ptr;
template <typename T> static constexpr auto vtable_for = vtable_t {
.name = [](const void * obj) { return static_cast<const T*>(obj)->name(); },
.count = [](void * obj) { return static_cast<T*>(obj)->count(); }
};
template <typename T> interfaceA(T & obj): object{&obj}, vtable_ptr{&vtable_for<T>} { }
std::string_view name() const {
return vtable_ptr->name(object);
}
int count() {
return vtable_ptr->count(object);
}
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels