Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2003-05-30 22:15:56


   There are two member functions that I think would be very useful for
tuples.
The first is assign(). Its signature would by

template <class X1, ..., XN, Y1, ... YN>
tuple<X1, .. XN> &tuple<X1, .. XN>::assign(const Y1 &y1, ... const YN &yn)

If x is an object of type tuple<X1, X2, ..., XN> then
x.assign(y1, y2, ..., yn) should do element-by-element assignment, unless
for some i, Yi is type swallow_assign (as in ignore), in which case the i'th
element is left untouched. For example,

tuple<int, double, string> my_tuple;
my_tuple.assign(1, 0.5, "foo"); // value of my_tuple is now (1, 0.5, "foo")
my_tuple.assign(3, ignore, "bar"); // value of my_tuple is now (3, 0.5,
"bar")

   This could save typing. Also, since assign() would require one parameter
for every element of the tuple, using assign() makes it harder to forget to
assign to one element. Using "ignore" demonstrates that the coder
deliberately decided not to assign to one element and didn't simply forget.

The other feature that I would like is swap(). Its signature would be
template <class X1, ..., XN>
void tuple<X1, .. XN>::swap(tuple<X1, ..., XN> &other);

This would do an element-by element swap on the two tuples. This could be
much faster that the usual assignment-based swap if one of the Xi's is a
large type like string or vector. If all the types X1, .., XN have the
nothrow guarantee on swap() then so would the tuple.

Joe Gottman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk