From 9f3a6243bf8025dd2fa122199b8d24ee5e00e3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Fri, 3 Sep 2021 19:31:13 -0400 Subject: [PATCH] ENH: deprecate itk::EnableIf and the header which implements it It should be replaced by std::enable_if from STL. --- Documentation/ITK5MigrationGuide.md | 1 + Modules/Core/Common/include/itkEnableIf.h | 8 ++ Modules/Core/Common/test/CMakeLists.txt | 1 - Modules/Core/Common/test/itkEnableIfTest.cxx | 107 ------------------- Utilities/Maintenance/BuildHeaderTest.py | 1 + 5 files changed, 10 insertions(+), 108 deletions(-) delete mode 100644 Modules/Core/Common/test/itkEnableIfTest.cxx diff --git a/Documentation/ITK5MigrationGuide.md b/Documentation/ITK5MigrationGuide.md index 1f8ad649bb5..a5b06b04d9b 100644 --- a/Documentation/ITK5MigrationGuide.md +++ b/Documentation/ITK5MigrationGuide.md @@ -79,6 +79,7 @@ To modernize your code base, replace: * `SimpleFastMutexLock` with `std::mutex`, and `#include "itkSimpleFastMutexLock.h"` with `#include `. * `FastMutexLock` with `std::mutex`, and `#include "itkFastMutexLock.h"` with `#include `. * `MutexLock` with `std::mutex`, and `#include "itkMutexLock.h"` with `#include `. + * `mpl::EnableIf::Type` with `std::enable_if_t`, and `#include "itkEnableIf.h"` with `#include `. Modern CMake requirement diff --git a/Modules/Core/Common/include/itkEnableIf.h b/Modules/Core/Common/include/itkEnableIf.h index fed23d28532..38924f5481d 100644 --- a/Modules/Core/Common/include/itkEnableIf.h +++ b/Modules/Core/Common/include/itkEnableIf.h @@ -18,6 +18,10 @@ #ifndef itkEnableIf_h #define itkEnableIf_h +#include "itkMacro.h" + +#if !defined(ITK_LEGACY_REMOVE) + namespace itk { /// \cond HIDE_META_PROGRAMMING @@ -159,4 +163,8 @@ using mpl::DisableIfC; /// \endcond } // namespace itk +#else // ITK_LEGACY_REMOVE +# error Use C++ 11 std::enable_if directly +#endif + #endif // itkEnableIf_h diff --git a/Modules/Core/Common/test/CMakeLists.txt b/Modules/Core/Common/test/CMakeLists.txt index 2692cf1528b..35620bca882 100644 --- a/Modules/Core/Common/test/CMakeLists.txt +++ b/Modules/Core/Common/test/CMakeLists.txt @@ -173,7 +173,6 @@ itkOptimizerParametersTest.cxx itkImageVectorOptimizerParametersHelperTest.cxx itkCompensatedSummationTest.cxx itkCompensatedSummationTest2.cxx -itkEnableIfTest.cxx itkImageRegionConstIteratorWithOnlyIndexTest.cxx itkImageRandomConstIteratorWithOnlyIndexTest.cxx itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx diff --git a/Modules/Core/Common/test/itkEnableIfTest.cxx b/Modules/Core/Common/test/itkEnableIfTest.cxx deleted file mode 100644 index 2ef5593103c..00000000000 --- a/Modules/Core/Common/test/itkEnableIfTest.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/*========================================================================= - * - * Copyright NumFOCUS - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *=========================================================================*/ - -#include "itkEnableIf.h" -#include "itkIsSame.h" -#include "itkNumericTraits.h" -#include "itkFixedArray.h" -#include -#include - -namespace -{ - -template -typename itk::EnableIfC::Type -test1() -{ - std::cout << "D is one" << std::endl; -} - -template -typename itk::EnableIfC::Type -test1() -{ - std::cout << "D is not one" << std::endl; -} - -template -typename itk::EnableIfC::Type -test2() -{ - std::cout << "T is one in size" << std::endl; -} - -template -typename itk::EnableIfC::Type -test2() -{ - std::cout << "T is not one in size" << std::endl; -} - - -template -typename itk::EnableIfC::ValueType>::Value>::Type -test3() -{ - std::cout << "T is enabled" << std::endl; -} - -template -typename itk::DisableIfC::ValueType>::Value>::Type -test3() -{ - std::cout << "T is disabled" << std::endl; -} - -template -typename itk::EnableIfC::ValueType>::Value>::Type -test4(const T &) -{ - std::cout << "T is enabled" << std::endl; -} - -template -typename itk::DisableIfC::ValueType>::Value>::Type -test4(const T &) -{ - std::cout << "T is disabled" << std::endl; -} - - -} // namespace - -int -itkEnableIfTest(int, char *[]) -{ - - test1<0>(); - test1<1>(); - test1<2>(); - - test2(); - test2(); - test2(); - - test3(); - test3>(); - - test4(1); - test4(itk::FixedArray()); - return EXIT_SUCCESS; -} diff --git a/Utilities/Maintenance/BuildHeaderTest.py b/Utilities/Maintenance/BuildHeaderTest.py index 93fd1b9b66d..a7280bfca2b 100755 --- a/Utilities/Maintenance/BuildHeaderTest.py +++ b/Utilities/Maintenance/BuildHeaderTest.py @@ -48,6 +48,7 @@ "itkBSplineDeformableTransform.h", # deprecated "vtkCaptureScreen.h", # these includes require VTK "itkMultiThreader.h", # Compatibility file, it should not be used + "itkEnableIf.h", # Compatibility file, it should not be used "itkViewImage.h", # Depends on VTK_RENDERING_BACKEND "QuickView.h", # Depends on VTK_RENDERING_BACKEND "itkBSplineDeformableTransformInitializer.h",