[Insight-developers] Questions about operator= in ITK

Brad King brad.king at kitware.com
Thu Mar 28 11:41:01 EDT 2013


On 03/28/2013 11:29 AM, Williams, Norman K wrote:
> There is a standard way to poison assignment and copy constructor, which
> is to declare them protected and then not implement them.  This is
> implemented consistently across all classes that derive ultimately from
> itk::LightObject.

I meant that *those* poisoned operators return void.  Others should not.

> The copy/swap paradigm is recommended a lot of places. I haven't
> encountered a case in ITK that it would make a difference.  The usual
> pattern suggested is
> 
> X& operator=(const X &x)
> {
>   X tmp(x);
>   swap(*this,x);

s/x/tmp/

However, see here for why to pass by value:

 http://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom
 http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/

-Brad


More information about the Insight-developers mailing list