Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add direct SmartPointer conversions to match raw Pointers
Some expect conversions were not available with SmartPointers. The patch adds direct conversion to SmartPointer<const T> from SmartPointer<T> and direct conversions when the raw pointer is convertible i.e. from derived to base classes. The prior implementation relied on implicit conversion to raw pointers and assignment from raw pointers to the smart pointer. These direct conversions support move semantics, which can bypass "expensive" atomic reference counting operations. The comparison operators are now non-member functions to have symmetric pointer comparisons. Additional std::nullptr_t argumented functions were added to avoid ambiguity created from SmartPointer's implicit conversion to raw pointers. Change-Id: I45e56547fbd22a08cef8350dd5f4d9383e1d3167
- Loading branch information
Showing
3 changed files
with
464 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is breaking builds.
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a specific failure to report? Or a proposed fix?
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a code that is failing. I have something similar when building SimpleITK. Is there a new convention that we need to follow here?
conversion from 'long' to 'spin::RGBImageType::Pointer' (aka 'SmartPointer<itk::Image<itk::RGBPixel<unsigned char>, 2> >') is ambiguous spin::RGBImageType::Pointer fg = NULL; ^ ~~~~ /usr/local/include/ITK-5.0/itkSmartPointer.h:68:13: note: candidate constructor constexpr SmartPointer (std::nullptr_t p) noexcept: ^ /usr/local/include/ITK-5.0/itkSmartPointer.h:94:3: note: candidate constructor SmartPointer (ObjectType *p) noexcept: ^
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, maybe you should update this wiki
https://itk.org/Wiki/ITK/Tutorials/DOs_and_DONTs
`` Do not call Delete() in an ITK smart pointer.
If you want to destroy a smart pointer object itksmartp, do:
the ITK smart pointer will determine whether the object should be "deleted".
``
Compiler is clang 4.0.1, Ubuntu 17.10 64Bit
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the API; the following code compiled.
spin::RGBImageType::Pointer fg = spin::RGBImageType::Pointer();
f9442c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the conversion to the ITK discussion group:
https://discourse.itk.org
Please keep in mind that ITK 5.0 is under active development of a major revision and some instability is expected.