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

Johnson, Hans J hans-johnson at uiowa.edu
Thu Aug 15 16:01:57 EDT 2013


Brad,

Could these be macros?

#if C++11
   DEFAULT_CONSTRUCTOR {}
#else
   DEFAULT_CONSTRUCTOR = default;
#end

From: Bradley Lowekamp <blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>>
Date: Thursday, August 15, 2013 2:51 PM
To: Matt McCormick <matt.mccormick at kitware.com<mailto:matt.mccormick at kitware.com>>
Cc: Slicer Development <slicer-devel at bwh.harvard.edu<mailto:slicer-devel at bwh.harvard.edu>>, ITK <insight-developers at itk.org<mailto:insight-developers at itk.org>>
Subject: Re: [Insight-developers] [slicer-devel] Improved readability of VTK derived class - What would you think of VTK_DISABLE_COPY macro ?

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<mailto: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<mailto: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<tel:%2B1%20919%20869%208849>

_______________________________________________
slicer-devel mailing list
slicer-devel at bwh.harvard.edu<mailto: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<mailto: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<mailto: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<mailto:slicer-devel-request at massmail.spl.harvard.edu> with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20130815/cebd422e/attachment.htm>


More information about the Insight-developers mailing list