jeudi 14 novembre 2019

Setting the value of an element in a tuple gives me error C2679

So suppose now I have a class like this

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

And now somewhere in my code, I want to change the value of an element in the tuple. Currently I'm using

std::get<2>(*tmp->m_tuple)  = ...;

to change the value of the third element in the tuple, which will always be an int. But at the compile time, I got an error C2679 saying : binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

I suspect that this is because that the value I used in the argument of std::get is a rvalue and std::get returns a rvalue as well. But I've tried converting it to lvalue before passing it to std::get and it didn't work.

So how can I manange to change the value of the tuple without modifying the rest of my code? Thanks !

Aucun commentaire:

Enregistrer un commentaire