可以使用 std::get通过索引从 std::tuple获取元素。 比方说,准备好了元组的元素如何按索引?
std::get
std::tuple
std::get returns a reference to the value. So you set the value like this:
std::get<0>(myTuple) = newValue;
This of course assumes that myTuple is non-const. You can even move items out of a tuple via std::move, by invoking it on the tuple:
myTuple
std::move
auto movedTo = std::get<0>(std::move(myTuple));
The non-const version of get returns a reference. You can assign to the reference. For example, suppose t is tuple, then: get<0>(t) = 3;
get
t
get<0>(t) = 3;