Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass real type of auto into template

So I have something for example

auto a = getMyTuple();

which will eventually be real type of std::tuple<(some args)>

Now I want to store this in a class which has a template since I dont know the type yet. Something along the lines of

template<typename T>
class my_tuple
{
  public:
  T mt;

  my_tuple(T t)
  {
    mt = t;
  }
};

My question is, is there a way to get the type returned by auto, so I can pass it into the template class like

my_tuple<getType(a)> myTup(a);
like image 719
user2770808 Avatar asked Sep 13 '25 04:09

user2770808


1 Answers

That's what decltype is for:

my_tuple<decltype(a)> myTup(a);
like image 102
Sam Varshavchik Avatar answered Sep 15 '25 20:09

Sam Varshavchik