my_fun can be implemented as follows using SFINAE.
namespace details{ struct A{}; struct B:A{};
Pay attention to passing a pointer to the Base or Derived class here, otherwise the compiler will complain about the ambiguous definition of the function.
The compiler will try to match the exact signature of my_fun_impl with the B pointer , this will succeed in the case of the container. Since the container will have begin () and end (), it is expected in the end type of the return value.
In the absence of the first type of container, the type will not match. And as we know, a Base class pointer can contain an object of a derived class, so the default match will succeed.
And the output of the following test code
int main() { my_fun(std::vector<int>{1,2,3}); my_fun(1); }
will be
Container Other than Container
Demo at coliru
gjha
source share