Is it possible to write a template function that would possess type information about the base class of the template argument? (assuming that the template argument derives from one class only)
So, I am looking for something like this:
template <class T>
auto f(T t) -> decltype(...) { // ... is some SFINAE magic that
// catches B, the base of T
std::cout << (B)t << std::endl;
}
EDIT: Some relevant background. I am writing a generic implementation of the A*
algorithm. The template argument is a Node
structure. So, the user might define:
struct NodeBase {
REFLECTABLE((double)g, (double)f)
// Using the REFLECTABLE macro as described here:
// http://stackoverflow.com/a/11744832/2725810
};
struct NodeData : public NodeBase {
using Base1 = NodeBase;
REFLECTABLE((double)F)
};
I would like to write a function that prints the contents of the node structure. REFLECTABLE
does all the hard work of extracting the fields of the struct
. However, when the user gives me a NodeData
instance, my function needs to print the contents of the NodeBase
component as well. I would like to later add overloads of my function for two and three base classes.