I have a template class and I want to know if it is possible to enforce that the template class type implements a certain interface, in particular I want to enforce that the type overloads the operator= method. In Java I would write:
public class Tree<T implements IComparable>{
public Tree(Vector<T> x){...}
}
What is the alternative in C++?
Just write the code assuming that it does. If it doesn’t, it will fail to compile when the user passes in the non-conforming type. There is no need for an explicit feature here. But why on earth would you ever need an interface like IComparable for this? Templates are duck typed.
But the template error might get nasty. You can use type traits and static assert to make this simpler. However, the Standard doesn’t provide a trait like this, so you’d have to write one with SFINAE.