When using the typical duck compilation inherent in style, is there a way to ensure that the template argument implements certain methods with specific signatures?
struct ProtocolT {
void g() const;
void h();
}
template <typename T>
void f(const T& x) {
x.g();
}
Of course, even without this, there is perfect type safety: if the template argument Tdoes not have a method used to implement the template function, the compiler will always complain.
But I believe that it would be desirable to clearly state that I class Tshould have all the methods indicated in some class ProtocolT. This would allow me to limit the design earlier in the development process, requiring methods from Tthat I have not yet used in the implementation of the template function.
ProtocolT, , , , T. (, ProtocolT , , ProtocolT , , .)