#include <iostream>
namespace detail
{
template <typename T> struct foo;
template <typename T>
struct foo<T*>
{
void operator()(const T* str) {std::cout << "ptr: " << str << std::endl;}
};
template <typename T, std::size_t N>
struct foo<T [N]>
{
void operator()(const T (&str)[N]) {std::cout << "arr: " << str << std::endl;}
};
}
template<typename T>
void foo(const T& t)
{
detail::template foo<T>()(t);
}
int main()
{
const char* ptr = "hello world";
foo("hello world"); // arr
foo(ptr); // ptr
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKbmFtZXNwYWNlIGRldGFpbAp7CiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4gc3RydWN0IGZvbzsKCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4KICAgIHN0cnVjdCBmb288VCo+CiAgICB7CiAgICAgICAgdm9pZCBvcGVyYXRvcigpKGNvbnN0IFQqIHN0cikge3N0ZDo6Y291dCA8PCAicHRyOiAiIDw8IHN0ciA8PCBzdGQ6OmVuZGw7fQogICAgfTsKCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgc3RkOjpzaXplX3QgTj4KICAgIHN0cnVjdCBmb288VCBbTl0+CiAgICB7CiAgICAgICAgdm9pZCBvcGVyYXRvcigpKGNvbnN0IFQgKCZzdHIpW05dKSB7c3RkOjpjb3V0IDw8ICJhcnI6ICIgPDwgc3RyIDw8IHN0ZDo6ZW5kbDt9CiAgICB9Owp9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgp2b2lkIGZvbyhjb25zdCBUJiB0KQp7CiAgICBkZXRhaWw6OnRlbXBsYXRlIGZvbzxUPigpKHQpOwp9CgppbnQgbWFpbigpCnsKICAgIGNvbnN0IGNoYXIqIHB0ciA9ICJoZWxsbyB3b3JsZCI7CiAgICBmb28oImhlbGxvIHdvcmxkIik7IC8vIGFycgogICAgZm9vKHB0cik7ICAgICAgICAgICAvLyBwdHIKICAgIHJldHVybiAwOwp9Cg==