2

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 ?

Rajeshwar
  • 11,179
  • 26
  • 86
  • 158

3 Answers3

7

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&>.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
4

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));
Alan
  • 1,895
  • 1
  • 10
  • 9
3

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).

gexicide
  • 38,535
  • 21
  • 92
  • 152