I want to check a provided template class for the existence of some methods at compile-time. Made-up example code:
template <class AudioSystem>
class Car {
public:
Car() {/*nothing related to AudioSystem*/}
void getsCalledLater(AudioSystem* a) {/*...*/}
void Verify() {
// check if class AudioSystem has function double hasFeature(int, double)
// check if class AudioSystem has function double getCreationDate()
}
~Car() {
Verify();
}
};
I do not have an AudioSystem
object when the constructor gets called, so I can't just do a test call for the methods. Also: I cannot assume that the default ctor of AudioSystem is available.
I found this question already here on SO, which pointed to
but I do not understand this innocent one-line solution:
// in Validation method:
T* (T::*test)() const = T::Clone; // checks for existence of T* T::Clone() const
Any help is appreciated.
(If it is not possible without having access to the default ctor, I might be able to drop that requirement.)