*
Ok, das const in der member function hatte ich nicht beachtet. Persönlich mag ich die Variante mit static_cast gar nicht, und es geht auch anders. Da da Rest (...) gleich ist, nur die Änderungen zur anderen Version. Das ist nun mit Konzepten umgesetzt, es sollte sich aber auch mit std::enable_if_t lösen lassen.
...
#include <type_traits>
...
class NF;
class CF;
template <typename T>
concept CheckFunction = std::same_as<T, NF>;
template <typename T>
concept CheckConstantFunction = std::same_as<T, CF>;
template <typename Function, typename R, typename Base, typename ... Types>
requires CheckConstantFunction<Function>
R func (Base* b, R (Base::* f)(Types ... args) const, Types ... args) {
return (b->*f)(args ...);
}
template <typename Function, typename R, typename Base, typename ... Types>
requires CheckFunction<Function>
R func (Base* b, R (Base::* f)(Types ... args), Types ... args) {
return (b->*f)(args ...);
}
int main () {
...
func<CF,double,Test>(&t,&Test::Setter);
func<NF,void,Test2,const MyBool*>(&t2,&Test2::Print,&b);
}