如何通过索引设置std :: tuple元素?


Answers:


131

std::get返回对该值的引用。因此,您可以这样设置值:

std::get<0>(myTuple) = newValue;

当然,这myTuple是非常量的。您甚至可以通过std::move在元组上调用,通过将其移出元组:

auto movedTo = std::get<0>(std::move(myTuple));

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.