D
dascandy
I think it would be possible to use SFINAE or something to detect
whether a certain function is present or not. I would like to use one
approach if it has the function (calling it for a result) and another
when it doesn't exist (calling a substitute function).
I've thought about using an interface instead, but that requires all
classes using it to implement that interface; moreover it won't ever
be called virtually. I would like to have it work mostly
"automatically".
My thoughts were along the lines of "pass the size of a function
pointer of that function in the respective class, if it doesn't exist
pass 0 instead". I can then select based on the sizeof whether it
supports the function. The problem is, if it has the function, both
templates match equally well. If it doesn't have it, the first is
eliminated based on sfinae but the second still matches, so it works
only if it doesn't exist.
Am I missing something? How can I make this work other than using an
interface for matching?
whether a certain function is present or not. I would like to use one
approach if it has the function (calling it for a result) and another
when it doesn't exist (calling a substitute function).
I've thought about using an interface instead, but that requires all
classes using it to implement that interface; moreover it won't ever
be called virtually. I would like to have it work mostly
"automatically".
My thoughts were along the lines of "pass the size of a function
pointer of that function in the respective class, if it doesn't exist
pass 0 instead". I can then select based on the sizeof whether it
supports the function. The problem is, if it has the function, both
templates match equally well. If it doesn't have it, the first is
eliminated based on sfinae but the second still matches, so it works
only if it doesn't exist.
Am I missing something? How can I make this work other than using an
interface for matching?