I am curious as to how std::function
can accept objects of different types as long as they have the same function call operator signature. For instance, these two structs are clearly unrelated, and yet, the same std::function object can be assigned to both of them.
struct A {
int operator()(int a) {
return a;
}
};
struct B {
int operator()(int a) {
return a;
}
};
int main() {
function<int(int)> f;
f = B{}; //OK
f = A{}; //OK
}
Could someone explain how is this possible?