Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boosttypes
From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-09-11 05:07:42


David Abrahams wrote:
>>> In generic code I strongly prefer
>>>
>>> T& operator=(T arg)
>>> {
>>> swap(*this, arg);
>>> return *this;
>>> }

> I'm just saying, I guess, that the form using the member
> forces me to define a swap member even though it's not really needed
> by generic code.

I think we should stick to the guideline to always have a swap member
function for a class, whenever the class has a custom free swap
function. Don't you agree?

BTW the swap member function offers a C++03 way to "move assign" an
rvalue:

  std::vector<int> generate_some_data(void);
  std::vector<int> my_data;
  // Move the result into my_data:
  generate_some_data().swap(my_data);

Peter Dimov wrote:
> Incidentally:
> http://aspn.activestate.com/ASPN/Mail/Message/boost/1140338
> "It doesn't compile with Borland C++Builder 4 or BCC 5.5.
>
> The next problem was associative_vector's assignment operator.
> Borland didn't recognise it as one and generated a default.
> Then it couldn't disambiguate the generated assignment operator
> and the one supplied. [...]
>
> My memory is correct on this one, too. I'm not sure why BCC 5.5.1
> didn't exhibit the problem in my tests.

Thanks Peter. Maybe it's a C++Builder 4/BCC 5.5 bug that was fixed by
BCC 5.5.1. :-) Anyway, neither of them are still at the regression
pages. Siliconman runs the tests on BCC 5.6.4, 5.8.2, and 5.9.3, while
JustSoftwareSolutions does BCC 5.8.2.

Thanks Joaquín, for already applying the patch from ticket #2313 to
multi_index_container::operator= Things still look fine at the
regression page
<www.boost.org/development/tests/trunk/developer/multi_index.html> but I
guess we have to wait a few days longer...

Kind regards, Niels


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