Hi,
I'm playing around with the reflection API, and often one has to pass a Table or a Struct to the functions there. However, when I have table or struct I know the type of, I have to issue an ugly reinterpret_cast to make the call - obviously this could be solved by having each table and struct in the generated code inherit from their corresponding reflection types, but I'm curious - was there a reason for not doing so (publically - Table is private-inherited)? Or is it simply that noone needed it and I should go open an Issue?
Here's a snippet I'd like to run:
void f(const Struct& s) {
...
}
void f2(const MyStructType& x) {
f(s); // <-- what I want
f(reinterpret_cast<const Struct&>(x)); // <-- what I have to do
}
Why use the reflection API if I know the type? One use case would be a general-purpose logger that uses the reflection description to log walk the table dynamically, but uses the concrete type to I can look up the right schema using some template traits tricks. The reinterpret_cast that has to be done after feels.. dirty ;)
Another use case would be to make overloads for tables and structs - again useful when writing generic code. Then I can have code like:
void f(const Struct& a) { ... }
void f(const Table& a) { ... }
template <typename T>
void x(const T& t) { f(t); }
.. and let the compile choose the right one.
Cheers,
Jacek