Preprocessor macro to get version of custom class

Hello,

is there some preprocessor macro that is capable of determining whether a custom class inheriting from TObject (with ClassDef) contains a method? Or maybe that just returns the class version?

The use-case would be to be able to change switch between class versions at compile time, without changing user code, e.g.:

MyObject *obj = new MyObject();
#if R__HasAttr(MyObject, SomeMethod) // or R__ClassVersion(MyObject) > 3
obj->SomeMethod();
#else
cout << "SomeMethod not yet implemented" << endl;
#endif

If I understand correctly, there is a way to do this at run time via TObject::Class_Version() and using a TMethodCall, so that, when switching to an old version, the compiler doesn’t complain that the method does not exist. But it would probably be nicer to have this check at compile time.

Thanks!

I don’t think so, but maybe @pcanal or @Axel knows better than me…

That’s currently not possible.

The closest we could get to is making MyObject::Class_Version() constexpr (currently it’s only static) in which case you could use if constexpr (since C++17).

Thanks! That would be a sensible thing to do, IMHO.