Just started exploring template feature for one of my task, I need to add some actions based on the typename in the template. Can someone point out what is wrong with this kind of structure:

```
#include <iostream>
#include <type_traits>

using namespace std;

template <typename T>
T foo()
{
    if(std::is_same<T, int>::value)
    {
        return 2;
    }
    if(std::is_same<T, std::string>::value)
    {
        return "apple";
    }
}

int main()
{
    std::cout<<"foo is: "<<foo<int>()<<std::endl;
    return 0;
}

```

I am wondering:

1. Why this *error* is happening `main.cpp:23:16: error: invalid conversion from ‘const char*’ to ‘int’` and how to get rid of it?
2. Is there a better way to do specific *actions* based on `typename` provided to the function?

**UPDATE:**

It turned out my program is using below C++17 compiler

**Attempt:**

I tried another approach to handle this case but failed miserably:

```
#include <iostream>
#include <type_traits>

using namespace std;

template <typename T, typename U>
T foo()
{
    T t = U;
    return t;
}

int main()
{
    std::cout<<"foo is: "<<foo<int, 1>()<<std::endl;
    return 0;
}

```

Anyone can point out what is going wrong here?