vendredi 15 novembre 2019

is_same and variadic template compile-time error invalid conversion

So I'm working on a project and I passed in different types of variables to my class to initialize the tuple. Now somewhere in my code I want to check if one of the tuple element, say the element at index 0, is of type int. And if it's of type int, I will change its value. I did that by using is_same and decltype to check if the types are same and if they are the same, I will perform the modifications, as I did in the main below. However, when I try to compile that code, the compiles gives me error saying invalid conversion. But since the types are different, shouldn't this if branch never be reached? Or is there another way to check for type and perform the modification as I want? Thanks

template <typename ...args>
class A
{
public:
   A(args&&...params)
   {
      m_tuple = new std::tuple<args...>(params...);
   }
   std::tuple<args...>* m_tuple;
};


int main()
{
  if (std::is_same<int,std::string>::value)
  {
      int i = "12";
  }
}

Aucun commentaire:

Enregistrer un commentaire