将元组的 const 引用传递给函子

passing a const reference of a tuple to a functor

我有一个 functor 需要修改元组值。所以我将 const reference 传递给它。

这是我的代码:

void operator() (thrust::tuple<const int&,const float&> tup)
{
    thrust::get<1> (tup) += 10;
    thrust::get<0> (tup) += 10;

}

但是我收到一个错误: error: expression must be a modifiable lvalue 很明显我没有修改引用,我只是修改元组引用的值。

..which needs to modify tuple values. So I am passing a const..

不要传递 const,你会没事的。