We observed that for std::any, the salient operations were as follows:
- Constructing a copy of the contained object
- Constructing a copy of the contained object "by move"
- Getting the typeid of the contained object
Suppose we were to add one to this set of salient operations? Let's say our set is:
- Constructing a copy of the contained object
- Constructing a copy of the contained object "by move"
- Getting the typeid of the contained object
- Calling the contained object with a particular fixed sequence of argument types A..., and converting the result to some particular fixed type R
The type-erasure of this set of operations corresponds to the standard library type std::function<R(A...)>!
int my_abs(int x) { return x < 0 ? -x : x; }
long unusual(long x, int y = 3) { return x + y; }
void test()
...