Andre Poenitz <[EMAIL PROTECTED]> writes:

| We are crossing unsafe ground:
| 
| This moves most parts of the "deep copy" from MathedIter to MathArray where
| it actually belongs. It's far from being nice and clean, but again I'd
| rather see it applied with this limited scope...
| 
| Andre'
| 
| -- 
| André Pönitz ........................................ [EMAIL PROTECTED]
| 
| ? .ChangeLog.swp
| ? .array.h.swp
| ? mathed25.diff
| ? .array.C.swp
| ? mathed26.diff
| Index: ChangeLog
| ===================================================================
| RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v
| retrieving revision 1.33
| diff -u -p -u -r1.33 ChangeLog
| --- ChangeLog 2001/02/19 10:18:21     1.33
| +++ ChangeLog 2001/02/19 12:14:24
| @@ -1,3 +1,10 @@
| +
| +2001-02-14  André Pönitz  <[EMAIL PROTECTED]>
| +
| +     * array.[Ch]: "deep" copy constructor and assignment operator for MathArray
| +
| +     * math_iter.[Ch]: seperate Copy() from Copy(int, int)
| +
|  2001-02-14  André Pönitz  <[EMAIL PROTECTED]>
|  
|       * array.[Ch]: remove constructor and  enums ARRAY_MIN_SIZE and ARRAY_STEP
| Index: array.C
| ===================================================================
| RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.C,v
| retrieving revision 1.7
| diff -u -p -u -r1.7 array.C
| --- array.C   2001/02/19 10:18:21     1.7
| +++ array.C   2001/02/19 12:14:24
| @@ -6,6 +6,8 @@
|  #endif
|  
|  #include "array.h"
| +#include "math_iter.h"
| +#include "math_inset.h"
|  
|  // Is this still needed? (Lgb)
|  static inline
| @@ -21,6 +23,39 @@ void * my_memcpy(void * ps_in, void cons
|  MathedArray::MathedArray()
|       : bf_(1, 0), last_(0)
|  {}
| +
| +
| +MathedArray::MathedArray(MathedArray const & array)
| +{
| +     operator=(array);
| +}

Don't do this.

Instead do what you have below in the constructor and
implement the assignment operator using the constructor (and perhaps a
swap method)

MathedArray & MathedArray::operator=(MathedArray const & array)
{
        MathedArray tmp(array); // this can throw
        bf_.swap(tmp.bf_); // swap is guaranteed to not throw.
        last_ = tmp.last_; // and assignment of PODs do not throw
        // btw. what about the pointers already stored in bf_?
        // will the insets they point to already be deleted? Or
        // will we leak?
}

Why do this you say?
Well, read development/CodeRules/Rules and the section about exception
safety. Bo doing it this way we get exception safefy and roll-back
semantics for free.

If the operator= thors an exception (out of mem f.ex.) we have not yet
really modified the array and we do not loose info.


        Lgb

Reply via email to