[Cs3] tuples
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Sep 29 20:04:42 EDT 2015
CS3 students,
Well, tuples do exist in C++. They are added in C++11 standard. They
are used in template programming. One use for them is to return
multiple values from a function without having to use
pass-by-reference. A helpful function is std::tie() that "unpacks" a
tie into singleton parameters. Something like this:
#include <tuple>
std::tuple<int,double> myfunc(); // function returning a tuple
int main(){
int a, double b;
std::tie(a,b) = myfunc() // return values are stored in a and b
}
Now, unlike pairs, tuples may have more than two elements. Tuple
elements do not have names (like first and second) and have to be
_unpacked_ as before to be accessed.
Thanks,
--
Mikhail
More information about the cs3
mailing list