I have something like this in my code
val = boost::make_tuple(objA , objB);
My question is does boost::make_tuple
make copies of objA and objB ?
I have something like this in my code
val = boost::make_tuple(objA , objB);
My question is does boost::make_tuple
make copies of objA and objB ?
Yes, the returned object is a boost::tuple<A, B>
which contains an A
object and a B
object, so they have to be copied from the arguments.
If you want a tuple of references, use boost::tie(objA, objB)
instead, which returns a boost::tuple<A&, B&>
.
Yes, if you want to it hold references, use boost::ref (or cref for const references)...
boost::make_tuple(boost::cref(objA), boost::cref(objB));
Yes it does. A tuple holds variables by value, so it must copy the values into the tuple. If you want only their references copied, use pointers instead, i.e., boost::make_tuple(&objA,&objB)
.