Skip to content

Commit

Permalink
ENH: Declare converting Point(v) constructors explicit
Browse files Browse the repository at this point in the history
Prevented implicit conversion of a value to `Point`. Aims to avoid
possible flaws, like the ones addressed by:

Pull request InsightSoftwareConsortium#3225
commit 5b71d63
"BUG: Quick-fix ContourSpatialObject::Update(), LINEAR_INTERPOLATION case"

Pull request InsightSoftwareConsortium#3228
commit 12a501c
"BUG: Fix `SetCenterInObjectSpace` calls in Registration test"

Pull request InsightSoftwareConsortium#3231
commit e4841aa
"STYLE: Clarify estimation ray position `RayCastInterpolateImageFunction`"

Deleted `Point(nullptr_t)`, especially to avoid `PointType p = 0`.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Feb 28, 2022
1 parent ddc0a37 commit 8825834
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Modules/Core/Common/include/itkPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,30 @@ class ITK_TEMPLATE_EXPORT Point : public FixedArray<TCoordRep, VPointDimension>
Point(const ValueType r[VPointDimension])
: BaseArray(r)
{}
/** Pass-through constructors for single values */

#if defined(ITK_LEGACY_REMOVE)
/** Prevents copy-initialization from `nullptr`, as well as from `0` (NULL). */
Point(std::nullptr_t) = delete;

/** Explicit constructors for single values */
template <typename TPointValueType>
explicit Point(const TPointValueType & v)
: BaseArray(v)
{}
explicit Point(const ValueType & v)
: BaseArray(v)
{}
#else
/** Pass-through constructors for single values
* \note ITK_LEGACY_REMOVE=ON will disallow implicit conversion from a single value. */
template <typename TPointValueType>
Point(const TPointValueType & v)
: BaseArray(v)
{}
Point(const ValueType & v)
: BaseArray(v)
{}
#endif

/** Explicit constructor for std::array. */
explicit Point(const std::array<ValueType, VPointDimension> & stdArray)
Expand Down

0 comments on commit 8825834

Please sign in to comment.