Boost logo

Boost :

From: Joerg Walter (jhr.walter_at_[hidden])
Date: 2002-04-17 14:23:17


Hi Peter,

you wrote:

> Salut,
>
> I'm currently puzzled by the matrix::swap function.
> Why is there an assertion checking the sizes of the
> swapped matrices in matrix.h:
>
> // Swapping
> NUMERICS_INLINE
> void swap (matrix &m) {
> check (this != &m, external_logic ());
> check (size1_ == m.size1_, bad_size ());
> check (size2_ == m.size2_, bad_size ());
> std::swap (size1_, m.size1_);
> std::swap (size2_, m.size2_);
> data_.swap (m.data_);
> }
>
> Best wishes,
> Peter

The precondition, that the sizes of the matrices shall be identical, is
checked, because swap() is used in assign_temporary(). May be, we could move
the precondition checks to assign_temporary().

But swap() for matrix views like matrix_range<> is intended to have deep
semantics similar to assignment, i.e. swap() should swap the elements of the
referenced matrices, but not the views. Here the precondition seems to be
reasonable.

So the interesting question arises, whether container and views should
require the same precondition on swap() or container's swap() should be
allowed to swap different sized matrices, too.

My current preference is obvious ;-)

Best regards

Joerg


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