Skip to content

Commit

Permalink
ENH: use std::enable_if instead of itk::mpl::EnableIf
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Sep 9, 2021
1 parent 2f732c0 commit 6b58ee8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
28 changes: 14 additions & 14 deletions Modules/Core/Common/include/itkVariableLengthVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

#include <cassert>
#include <algorithm>
#include <type_traits>
#include "itkNumericTraits.h"
#include "itkMetaProgrammingLibrary.h"
#include "itkEnableIf.h"
#include "itkIsBaseOf.h"
#include "itkIsNumber.h"
#include "itkPromoteType.h"
Expand Down Expand Up @@ -1052,7 +1052,7 @@ struct GetType
* \sa \c VariableLengthVectorExpression
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2>>, unsigned int>::Type
inline std::enable_if_t<mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2>>::Value, unsigned int>
GetSize(TExpr1 const & lhs, TExpr2 const & rhs)
{
(void)rhs;
Expand All @@ -1071,7 +1071,7 @@ GetSize(TExpr1 const & lhs, TExpr2 const & rhs)
* \sa \c VariableLengthVectorExpression
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::Not<mpl::IsArray<TExpr2>>>, unsigned int>::Type
inline std::enable_if_t<mpl::And<mpl::IsArray<TExpr1>, mpl::Not<mpl::IsArray<TExpr2>>>::Value, unsigned int>
GetSize(TExpr1 const & lhs, TExpr2 const & itkNotUsed(rhs))
{
return lhs.Size();
Expand All @@ -1087,7 +1087,7 @@ GetSize(TExpr1 const & lhs, TExpr2 const & itkNotUsed(rhs))
* \sa \c VariableLengthVectorExpression
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr2>, mpl::Not<mpl::IsArray<TExpr1>>>, unsigned int>::Type
inline std::enable_if_t<mpl::And<mpl::IsArray<TExpr2>, mpl::Not<mpl::IsArray<TExpr1>>>::Value, unsigned int>
GetSize(TExpr1 const & itkNotUsed(lhs), TExpr2 const & rhs)
{
return rhs.Size();
Expand Down Expand Up @@ -1261,8 +1261,8 @@ struct VariableLengthVectorExpression
* \sa \c mpl::IsArray<> to know the exact array types recognized as \em array by this traits
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<Details::op::CanBeAddedOrSubtracted<TExpr1, TExpr2>,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Plus>>::Type
inline std::enable_if_t<Details::op::CanBeAddedOrSubtracted<TExpr1, TExpr2>::Value,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Plus>>
operator+(TExpr1 const & lhs, TExpr2 const & rhs)
{
return VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Plus>(lhs, rhs);
Expand All @@ -1278,8 +1278,8 @@ operator+(TExpr1 const & lhs, TExpr2 const & rhs)
* \sa \c mpl::IsArray<> to know the exact array types recognized as \em array by this traits
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<Details::op::CanBeAddedOrSubtracted<TExpr1, TExpr2>,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Sub>>::Type
inline std::enable_if_t<Details::op::CanBeAddedOrSubtracted<TExpr1, TExpr2>::Value,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Sub>>
operator-(TExpr1 const & lhs, TExpr2 const & rhs)
{
return VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Sub>(lhs, rhs);
Expand All @@ -1294,8 +1294,8 @@ operator-(TExpr1 const & lhs, TExpr2 const & rhs)
* \sa \c mpl::IsArray<> to know the exact array types recognized as \em array by this traits
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<Details::op::CanBeMultiplied<TExpr1, TExpr2>,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Mult>>::Type
inline std::enable_if_t<Details::op::CanBeMultiplied<TExpr1, TExpr2>::Value,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Mult>>
operator*(TExpr1 const & lhs, TExpr2 const & rhs)
{
return VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Mult>(lhs, rhs);
Expand All @@ -1309,8 +1309,8 @@ operator*(TExpr1 const & lhs, TExpr2 const & rhs)
* \sa \c mpl::IsArray<> to know the exact array types recognized as \em array by this traits
*/
template <typename TExpr1, typename TExpr2>
inline typename mpl::EnableIf<Details::op::CanBeDivided<TExpr1, TExpr2>,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Div>>::Type
inline std::enable_if_t<Details::op::CanBeDivided<TExpr1, TExpr2>::Value,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Div>>
operator/(TExpr1 const & lhs, TExpr2 const & rhs)
{
return VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Div>(lhs, rhs);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ operator<<(std::ostream & os, VariableLengthVectorExpression<TExpr1, TExpr2, TBi
* \relates itk::VariableLengthVectorExpression
*/
template <typename TExpr>
inline typename mpl::EnableIf<mpl::IsArray<TExpr>, typename TExpr::RealValueType>::Type
inline std::enable_if_t<mpl::IsArray<TExpr>::Value, typename TExpr::RealValueType>
GetNorm(TExpr const & v)
{
return static_cast<typename TExpr::RealValueType>(std::sqrt(static_cast<double>(GetSquaredNorm(v))));
Expand All @@ -1353,7 +1353,7 @@ GetNorm(TExpr const & v)
* \relates itk::VariableLengthVectorExpression
*/
template <typename TExpr>
inline typename mpl::EnableIf<mpl::IsArray<TExpr>, typename TExpr::RealValueType>::Type
inline std::enable_if_t<mpl::IsArray<TExpr>::Value, typename TExpr::RealValueType>
GetSquaredNorm(TExpr const & v)
{
using RealValueType = typename TExpr::RealValueType;
Expand Down
6 changes: 3 additions & 3 deletions Modules/IO/ImageBase/include/itkConvertPixelBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "itkObject.h"
#include "itkNumericTraits.h"
#include "itkEnableIf.h"
#include <type_traits> // for enable_if

namespace itk
{
Expand Down Expand Up @@ -167,11 +167,11 @@ class ITK_TEMPLATE_EXPORT ConvertPixelBuffer
* world of rgb<float> or rgb<double> alpha would have to be 1.0
*/
template <typename UComponentType>
static typename DisableIfC<NumericTraits<UComponentType>::IsInteger, UComponentType>::Type
static std::enable_if_t<!NumericTraits<UComponentType>::IsInteger, UComponentType>
DefaultAlphaValue();

template <typename UComponentType>
static typename EnableIfC<NumericTraits<UComponentType>::IsInteger, UComponentType>::Type
static std::enable_if_t<NumericTraits<UComponentType>::IsInteger, UComponentType>
DefaultAlphaValue();
};
} // namespace itk
Expand Down
4 changes: 2 additions & 2 deletions Modules/IO/ImageBase/include/itkConvertPixelBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ namespace itk

template <typename InputPixelType, typename OutputPixelType, typename OutputConvertTraits>
template <typename UComponentType>
typename DisableIfC<NumericTraits<UComponentType>::IsInteger, UComponentType>::Type
std::enable_if_t<!NumericTraits<UComponentType>::IsInteger, UComponentType>
ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits>::DefaultAlphaValue()
{
return NumericTraits<UComponentType>::One;
}

template <typename InputPixelType, typename OutputPixelType, typename OutputConvertTraits>
template <typename UComponentType>
typename EnableIfC<NumericTraits<UComponentType>::IsInteger, UComponentType>::Type
std::enable_if_t<NumericTraits<UComponentType>::IsInteger, UComponentType>
ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits>::DefaultAlphaValue()
{
return NumericTraits<UComponentType>::max();
Expand Down
8 changes: 3 additions & 5 deletions Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*=========================================================================*/

#include "itkNiftiImageIOTest.h"
#include "itkEnableIf.h"
#include <type_traits> // for enable_if
#include <limits>

template <typename ScalarType>
void
Decrement(ScalarType & value,
typename itk::DisableIfC<std::numeric_limits<ScalarType>::is_signed, ScalarType>::Type * = nullptr)
Decrement(ScalarType & value, std::enable_if_t<!std::numeric_limits<ScalarType>::is_signed, ScalarType> * = nullptr)
{
if (value > 1)
{
Expand All @@ -33,8 +32,7 @@ Decrement(ScalarType & value,

template <typename ScalarType>
void
Decrement(ScalarType & value,
typename itk::EnableIfC<std::numeric_limits<ScalarType>::is_signed, ScalarType>::Type * = nullptr)
Decrement(ScalarType & value, std::enable_if_t<std::numeric_limits<ScalarType>::is_signed, ScalarType> * = nullptr)
{
if (value > -std::numeric_limits<ScalarType>::max() + 1)
{
Expand Down

0 comments on commit 6b58ee8

Please sign in to comment.