Are there any patterns for defining compile-time class contracts?
My goals are:
- maintainability - in a large codebase, it would be very useful to specify and validate the compile-time contracts so the dependencies are obvious.
- quality error messages - instead of complaining that a line of code deep inside the template can't call a method, it would be better to surface the lack of contract fulfillment.
Something like...
class StaticContract {
static void Method();
};
class MeetsContract {
static void Method();
};
// T must have all methods of StaticContract, or compile-time error.
template <class T /* : StaticContract */>
void DoSomething(T t);
I'd accept:
- way of enforcing the contract at compile time
- patterns for capturing / documenting compile-time contracts
- solutions for the subsets of {static methods, member methods, typedefs, etc}
- solutions that redefine my problem statement
- best practices