Skip to content

Commit

Permalink
ENH: replace instances of mpl::IsSame by std::is_same
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Sep 10, 2021
1 parent 978bc5b commit c28930c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
22 changes: 11 additions & 11 deletions Modules/Core/Common/include/itkInPlaceImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define itkInPlaceImageFilter_h

#include "itkImageToImageFilter.h"
#include "itkIsSame.h"
#include <type_traits>

namespace itk
{
Expand Down Expand Up @@ -147,7 +147,15 @@ class ITK_TEMPLATE_EXPORT InPlaceImageFilter : public ImageToImageFilter<TInputI
void
AllocateOutputs() override
{
this->InternalAllocateOutputs(IsSame<TInputImage, TOutputImage>());
if (std::is_same<TInputImage, TOutputImage>::value)
{
this->InternalAllocateOutputs();
}
else // the type are different we can't run in place
{
this->m_RunningInPlace = false;
this->Superclass::AllocateOutputs();
}
}

/** InPlaceImageFilter may transfer ownership of the input bulk data
Expand All @@ -169,16 +177,8 @@ class ITK_TEMPLATE_EXPORT InPlaceImageFilter : public ImageToImageFilter<TInputI
itkGetConstMacro(RunningInPlace, bool);

private:
// the type are different we can't run in place
void
InternalAllocateOutputs(const FalseType &)
{
this->m_RunningInPlace = false;
this->Superclass::AllocateOutputs();
}

void
InternalAllocateOutputs(const TrueType &);
InternalAllocateOutputs();

bool m_InPlace{ true }; // enable the possibility of in-place
bool m_RunningInPlace{ false };
Expand Down
9 changes: 3 additions & 6 deletions Modules/Core/Common/include/itkInPlaceImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ InPlaceImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream & os, Inde

template <typename TInputImage, typename TOutputImage>
void
InPlaceImageFilter<TInputImage, TOutputImage>::InternalAllocateOutputs(const TrueType &)
InPlaceImageFilter<TInputImage, TOutputImage>::InternalAllocateOutputs()
{
// Use ProcessObject's GetInput method to get a DataObject pointer,
// then perform a dynamic_cast to the expected InputImageType. This
Expand Down Expand Up @@ -90,10 +90,7 @@ InPlaceImageFilter<TInputImage, TOutputImage>::InternalAllocateOutputs(const Tru
// remove the input's hold on the bulk data.
//
OutputImagePointer inputAsOutput = nullptr;
if (IsSame<TInputImage, TOutputImage>())
{
inputAsOutput = reinterpret_cast<TOutputImage *>(const_cast<TInputImage *>(inputPtr));
}
inputAsOutput = reinterpret_cast<TOutputImage *>(const_cast<TInputImage *>(inputPtr));
itkAssertOrThrowMacro(inputAsOutput.IsNotNull(), "Unable to convert input image to output image as expected!");

this->GraftOutput(inputAsOutput);
Expand Down Expand Up @@ -131,7 +128,7 @@ template <typename TInputImage, typename TOutputImage>
bool
InPlaceImageFilter<TInputImage, TOutputImage>::CanRunInPlace() const
{
return IsSame<TInputImage, TOutputImage>();
return std::is_same<TInputImage, TOutputImage>::value;
}

template <typename TInputImage, typename TOutputImage>
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkIsBaseOf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define itkIsBaseOf_h

#include "itkIsConvertible.h"
#include "itkIsSame.h"
#include <type_traits>

namespace itk
{
Expand All @@ -40,7 +40,7 @@ template <typename TBase, typename TDerived>
struct IsBaseOf
{
static constexpr bool Value =
IsConvertible<const TDerived *, const TBase *>::Value && !IsSame<const TBase *, const void *>::Value;
IsConvertible<const TDerived *, const TBase *>::Value && !std::is_same<const TBase *, const void *>::value;
};
} // end namespace mpl

Expand Down
47 changes: 24 additions & 23 deletions Modules/Core/Common/test/itkMetaProgrammingLibraryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*
*=========================================================================*/

#include <type_traits>

#include "itkMetaProgrammingLibrary.h"
#include "itkIsSame.h"
#include "itkStaticAssert.h"


Expand All @@ -43,18 +44,18 @@ itkMetaProgrammingLibraryTest(int, char *[])
itkStaticAssert((OrC<false, false>::Value == false), "Unit test failed");

// Or between types
itkStaticAssert((IsSame<Or<TrueType, TrueType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<TrueType, FalseType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<TrueType, TrueType, FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<FalseType, FalseType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<TrueType, FalseType, FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<FalseType, TrueType, FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<FalseType, FalseType, FalseType>::Type, FalseType>::Value), "Unit test failed");

itkStaticAssert((IsSame<Or<TrueType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<TrueType, FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<FalseType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Or<FalseType, FalseType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

itkStaticAssert((std::is_same<Or<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// And between constants
itkStaticAssert((AndC<true, true>::Value == true), "Unit test failed");
Expand All @@ -63,10 +64,10 @@ itkMetaProgrammingLibraryTest(int, char *[])
itkStaticAssert((AndC<false, false>::Value == false), "Unit test failed");

// And between types
itkStaticAssert((IsSame<And<TrueType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<And<TrueType, FalseType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((IsSame<And<FalseType, TrueType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((IsSame<And<FalseType, FalseType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((std::is_same<And<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<TrueType, FalseType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<FalseType, TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// Xor between constants
itkStaticAssert((XorC<true, true>::Value == false), "Unit test failed");
Expand All @@ -75,18 +76,18 @@ itkMetaProgrammingLibraryTest(int, char *[])
itkStaticAssert((XorC<false, false>::Value == false), "Unit test failed");

// Xor between types
itkStaticAssert((IsSame<Xor<TrueType, TrueType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Xor<TrueType, FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Xor<FalseType, TrueType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Xor<FalseType, FalseType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<TrueType, TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// Not between constants
itkStaticAssert((NotC<true>::Value == false), "Unit test failed");
itkStaticAssert((NotC<false>::Value == true), "Unit test failed");

// Not between types
itkStaticAssert((IsSame<Not<TrueType>::Type, FalseType>::Value), "Unit test failed");
itkStaticAssert((IsSame<Not<FalseType>::Type, TrueType>::Value), "Unit test failed");
itkStaticAssert((std::is_same<Not<TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Not<FalseType>::Type, TrueType>::value), "Unit test failed");

#endif

Expand Down
31 changes: 16 additions & 15 deletions Modules/Core/Common/test/itkPromoteType.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "itkPromoteType.h"
#include <complex>
#include <itkIsSame.h>
#include <type_traits>

namespace itk
{
Expand Down Expand Up @@ -54,21 +54,22 @@ itkPromoteType(int, char *[])
// the following list able to hold their entire value range: int, unsigned
// int, long, unsigned long, long long, unsigned long long.

static_assert((IsSame<PromoteType<signed char, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<signed char, short>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<unsigned char, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<unsigned char, unsigned int>::Type, unsigned int>::Value), "test failed");
static_assert((IsSame<PromoteType<int, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<short, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<double, int>::Type, double>::Value), "test failed");
static_assert((IsSame<PromoteType<float, int>::Type, float>::Value), "test failed");
static_assert((IsSame<PromoteType<long, int>::Type, long>::Value), "test failed");
static_assert((IsSame<PromoteType<long long, int>::Type, long long>::Value), "test failed");
static_assert((IsSame<PromoteType<int, long long>::Type, long long>::Value), "test failed");
static_assert((IsSame<PromoteType<long, long double>::Type, long double>::Value), "test failed");
static_assert((IsSame<PromoteType<double, std::complex<double>>::Type, std::complex<double>>::Value), "test failed");
static_assert((std::is_same<PromoteType<signed char, int>::Type, int>::value), "test failed");
static_assert((std::is_same<PromoteType<signed char, short>::Type, int>::value), "test failed");
static_assert((std::is_same<PromoteType<unsigned char, int>::Type, int>::value), "test failed");
static_assert((std::is_same<PromoteType<unsigned char, unsigned int>::Type, unsigned int>::value), "test failed");
static_assert((std::is_same<PromoteType<int, int>::Type, int>::value), "test failed");
static_assert((std::is_same<PromoteType<short, int>::Type, int>::value), "test failed");
static_assert((std::is_same<PromoteType<double, int>::Type, double>::value), "test failed");
static_assert((std::is_same<PromoteType<float, int>::Type, float>::value), "test failed");
static_assert((std::is_same<PromoteType<long, int>::Type, long>::value), "test failed");
static_assert((std::is_same<PromoteType<long long, int>::Type, long long>::value), "test failed");
static_assert((std::is_same<PromoteType<int, long long>::Type, long long>::value), "test failed");
static_assert((std::is_same<PromoteType<long, long double>::Type, long double>::value), "test failed");
static_assert((std::is_same<PromoteType<double, std::complex<double>>::Type, std::complex<double>>::value),
"test failed");

static_assert((IsSame<PromoteType<std::complex<int>, std::complex<double>>::Type, std::complex<double>>::Value),
static_assert((std::is_same<PromoteType<std::complex<int>, std::complex<double>>::Type, std::complex<double>>::value),
"test failed");
return EXIT_SUCCESS;
}

0 comments on commit c28930c

Please sign in to comment.