[Insight-developers] [slicer-devel] Improved readability of VTK derived class - What would you think of VTK_DISABLE_COPY macro ?

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Aug 15 15:51:05 EDT 2013


New with C++11 you can explicitly delete these methods. It may give better compiler error messages. It may be worth the try compile to give a useful error message to users.

I messed a bit with in in SimpleITK, though I don't think I turned it on:
https://github.com/SimpleITK/SimpleITK/blob/master/Code/Common/include/sitkNonCopyable.h#L60

I think it would make the change to the newer C++ code easier.

Brad

On Aug 15, 2013, at 3:43 PM, Matt McCormick <matt.mccormick at kitware.com> wrote:

> Hi Jc,
> 
> I like the idea -- it is more explicit, and it saves time.  What do members of the ITK community think of an itkDisableCopy(MyClass) macro?
> 
> Thanks,
> Matt
> 
> 
> On Thu, Aug 15, 2013 at 6:11 PM, Jean-Christophe Fillion-Robin <jchris.fillionr at kitware.com> wrote:
> Hi Folks, 
> 
> On the VTK developer list, I recently discussed the introduction of a new VTK macro named "VTK_DISABLE_COPY" [1][2] that would allow to easily disable assignment and copy constructor in VTK class deriving from vtkObject. 
> 
> 
> Note that disabling these constructors for class deriving from vtkObject IS mandatory, it has to be done. You probably already copied this two constructor lines over and over ... 
> 
> 
> This macro would be similar to what is done in Qt with Q_DISABLE_COPY. For details [3]
> 
> 
> For example, to declare the class MyClass, you would do .... 
> 
> // -----------------
> class MyClass : public vtkObject
> {
> 
>   private:
>     VTK_DISABLE_COPY(MyClass)
> };
> // -----------------
> 
> 
> 
> instead of 
> 
> 
> 
> // -----------------
> class MyClass : public vtkObject
> {
> 
>   private:
>      MyClass(const MyClass &);
>      MyClass &operator=(const MyClass &);
> };
> // -----------------
> 
> 
> 
> The more people reply to this email, the more chance we will have to see this macro added to VTK6. 
> 
> 
> Let us know what you think.
> 
> 
> Thanks
> Jc
> 
> 
> [1] http://vtk.1045678.n5.nabble.com/Implicit-copy-constructors-in-VTK-tp5722193p5722205.html
> 
> [2] http://vtk.1045678.n5.nabble.com/Implicit-copy-constructors-in-VTK-tp5722193p5722217.html
> 
> [3] http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#Q_DISABLE_COPY
> 
> -- 
> +1 919 869 8849
> 
> _______________________________________________
> slicer-devel mailing list
> slicer-devel at bwh.harvard.edu
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
> To unsubscribe: send email to slicer-devel-request at massmail.spl.harvard.edu with unsubscribe as the subject
> http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
> 
> _______________________________________________
> slicer-devel mailing list
> slicer-devel at bwh.harvard.edu
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
> To unsubscribe: send email to slicer-devel-request at massmail.spl.harvard.edu with unsubscribe as the subject
> http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20130815/99bfbbc1/attachment.htm>


More information about the Insight-developers mailing list