// define a function with 3 return valuestuple<int, int, double> add_multiply_divide(int a, int b){ return make_tuple(a+b, a*b, double(a)/b);}// call the functionint a, b; double c;tie (a, b, c) = add_multiply_divide(1, 2);
Returning more then one thing?
Lambda Library has support for tuples:
The problem with all tuple classes is that they support a fixed number of parameters. One might as well use pair:
Of course, this is messy because you have to access elements reverse hierarchically:
Yuck! Of course, we could reverse the hierarchy by declaring the int before the pair, but that changes nothing. So we declare tuple types. Okay, now how do I create a 5-element tuple (without explicitly defining a structure to hold 5 elements)? (This is actually a standing C/C++ problem; if you can solve it you''ll probably be famous (within CS circles), but not rich).
Some languages do intrinsically support tuples though.
Start Here!
typedef pair<pair<pair<pair<int, int>, int>, int>, int> quad_tuple;
Of course, this is messy because you have to access elements reverse hierarchically:
quad_tuple qt;// set the fourth elementqt.second = 4;qt.first.second = 3;qt.first.first.second = 2;qt.first.first.first = 1;
Yuck! Of course, we could reverse the hierarchy by declaring the int before the pair, but that changes nothing. So we declare tuple types. Okay, now how do I create a 5-element tuple (without explicitly defining a structure to hold 5 elements)? (This is actually a standing C/C++ problem; if you can solve it you''ll probably be famous (within CS circles), but not rich).
Some languages do intrinsically support tuples though.
Start Here!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement