I have some values held in a tuple, and I am looking to add another tuple to it element-wise. So I would like functionality like this:
std::tuple
Here is an operator definition for syntax #1:
template std::tuple operator + (const std::tuple& lhs, const std::tuple& rhs)
{
return std::make_tuple(std::get<0>(lhs) + std::get<0>(rhs), std::get<1>(lhs) + std::get<1>(rhs));
}
Syntax #2 and #3 are not possible without creating a custom struct, because they can only be defined as members of the classes they operate on (and you can't touch existing classes in namespace std
).