From 207e332626761be8ff34ef006025a8ca9a55ebb8 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Fri, 31 May 2024 16:58:38 -0500 Subject: [PATCH 1/2] ENH: Remove legacy designation for outdated defines --- .../TestKernel/include/itkTestingMacros.h | 53 +++++-------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/Modules/Core/TestKernel/include/itkTestingMacros.h b/Modules/Core/TestKernel/include/itkTestingMacros.h index 1d7d3a10721..81eb637ef44 100644 --- a/Modules/Core/TestKernel/include/itkTestingMacros.h +++ b/Modules/Core/TestKernel/include/itkTestingMacros.h @@ -35,47 +35,20 @@ namespace itk // DEPRECATED: These macros are left here for compatibility. // In the future, they will be removed in favor of the "ITK_" prefixed // versions. -#if defined(ITK_FUTURE_LEGACY_REMOVE) +#define EXERCISE_BASIC_OBJECT_METHODS \ + static_assert(false, "Replace EXERCISE_BASIC_OBJECT_METHODS with ITK_EXERCISE_BASIC_OBJECT_METHODS") +#define TRY_EXPECT_EXCEPTION static_assert(false, "Replace TRY_EXPECT_EXCEPTION with ITK_TRY_EXPECT_EXCEPTION") +#define TRY_EXPECT_NO_EXCEPTION static_assert(fasle, "Replace TRY_EXPECT_NO_EXCEPTION with ITK_TRY_EXPECT_NO_EXCEPTION") +#define TEST_EXPECT_TRUE_STATUS_VALUE \ + static_assert(false, "Replace TEST_EXPECT_TRUE_STATUS_VALUE with ITK_TEST_EXPECT_TRUE_STATUS_VALUE") +#define TEST_EXPECT_TRUE static_assert(false, "Replace TEST_EXPECT_TRUE with ITK_TEST_EXPECT_TRUE") +#define TEST_EXPECT_EQUAL_STATUS_VALUE "Replace TEST_EXPECT_EQUAL_STATUS_VALUE with ITK_TEST_EXPECT_EQUAL_STATUS_VALUE" +#define TEST_EXPECT_EQUAL static_assert(false, "Replace TEST_EXPECT_EQUAL with ITK_TEST_EXPECT_EQUAL") +#define TEST_SET_GET static_assert(false, "Replace TEST_SET_GET with ITK_TEST_SET_GET") +#define TEST_SET_GET_VALUE static_assert(false, "Replace TEST_SET_GET_VALUE with ITK_TEST_SET_GET_VALUE") +#define TEST_SET_GET_NULL_VALUE static_assert(false, "Replace TEST_SET_GET_NULL_VALUE with ITK_TEST_SET_GET_NULL_VALUE") +#define TEST_SET_GET_BOOLEAN static_assert(false, "Replace TEST_SET_GET_BOOLEAN with ITK_TEST_SET_GET_BOOLEAN") -# if defined(__clang__) || defined(__GNUC__) -# pragma GCC poison EXERCISE_BASIC_OBJECT_METHODS -# pragma GCC poison TRY_EXPECT_EXCEPTION -# pragma GCC poison TRY_EXPECT_NO_EXCEPTION -# pragma GCC poison TEST_EXPECT_TRUE_STATUS_VALUE -# pragma GCC poison TEST_EXPECT_TRUE -# pragma GCC poison TEST_EXPECT_EQUAL_STATUS_VALUE -# pragma GCC poison TEST_EXPECT_EQUAL -# pragma GCC poison TEST_SET_GET -# pragma GCC poison TEST_SET_GET_VALUE -# pragma GCC poison TEST_SET_GET_NULL_VALUE -# pragma GCC poison TEST_SET_GET_BOOLEAN -# else -# define EXERCISE_BASIC_OBJECT_METHODS "Replace EXERCISE_BASIC_OBJECT_METHODS with ITK_EXERCISE_BASIC_OBJECT_METHODS" -# define TRY_EXPECT_EXCEPTION "Replace TRY_EXPECT_EXCEPTION with ITK_TRY_EXPECT_EXCEPTION" -# define TRY_EXPECT_NO_EXCEPTION "Replace TRY_EXPECT_NO_EXCEPTION with ITK_TRY_EXPECT_NO_EXCEPTION" -# define TEST_EXPECT_TRUE_STATUS_VALUE "Replace TEST_EXPECT_TRUE_STATUS_VALUE with ITK_TEST_EXPECT_TRUE_STATUS_VALUE" -# define TEST_EXPECT_TRUE "Replace TEST_EXPECT_TRUE with ITK_TEST_EXPECT_TRUE" -# define TEST_EXPECT_EQUAL_STATUS_VALUE \ - "Replace TEST_EXPECT_EQUAL_STATUS_VALUE with ITK_TEST_EXPECT_EQUAL_STATUS_VALUE" -# define TEST_EXPECT_EQUAL "Replace TEST_EXPECT_EQUAL with ITK_TEST_EXPECT_EQUAL" -# define TEST_SET_GET "Replace TEST_SET_GET with ITK_TEST_SET_GET" -# define TEST_SET_GET_VALUE "Replace TEST_SET_GET_VALUE with ITK_TEST_SET_GET_VALUE" -# define TEST_SET_GET_NULL_VALUE "Replace TEST_SET_GET_NULL_VALUE with ITK_TEST_SET_GET_NULL_VALUE" -# define TEST_SET_GET_BOOLEAN "Replace TEST_SET_GET_BOOLEAN with ITK_TEST_SET_GET_BOOLEAN" -# endif -#else -# define EXERCISE_BASIC_OBJECT_METHODS ITK_EXERCISE_BASIC_OBJECT_METHODS -# define TRY_EXPECT_EXCEPTION ITK_TRY_EXPECT_EXCEPTION -# define TRY_EXPECT_NO_EXCEPTION ITK_TRY_EXPECT_NO_EXCEPTION -# define TEST_EXPECT_TRUE_STATUS_VALUE ITK_TEST_EXPECT_TRUE_STATUS_VALUE -# define TEST_EXPECT_TRUE ITK_TEST_EXPECT_TRUE -# define TEST_EXPECT_EQUAL_STATUS_VALUE ITK_TEST_EXPECT_EQUAL_STATUS_VALUE -# define TEST_EXPECT_EQUAL ITK_TEST_EXPECT_EQUAL -# define TEST_SET_GET ITK_TEST_SET_GET -# define TEST_SET_GET_VALUE ITK_TEST_SET_GET_VALUE -# define TEST_SET_GET_NULL_VALUE ITK_TEST_SET_GET_NULL_VALUE -# define TEST_SET_GET_BOOLEAN ITK_TEST_SET_GET_BOOLEAN -#endif /* clang-format off */ #if defined(__GNUC__) From fdfe8c45f0ded269a58c9c8d972704c1e245b8f4 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Fri, 31 May 2024 16:39:29 -0500 Subject: [PATCH 2/2] ENH: Remove ITK implementation of standard C++11 features. --- Modules/Core/Common/include/itkEnableIf.h | 151 +----------------- Modules/Core/Common/include/itkIsBaseOf.h | 35 +--- .../Core/Common/include/itkIsConvertible.h | 72 +-------- Modules/Core/Common/include/itkIsSame.h | 41 +---- Modules/Core/Common/include/itkStaticAssert.h | 15 +- 5 files changed, 9 insertions(+), 305 deletions(-) diff --git a/Modules/Core/Common/include/itkEnableIf.h b/Modules/Core/Common/include/itkEnableIf.h index f90a66a9abb..d0226979a80 100644 --- a/Modules/Core/Common/include/itkEnableIf.h +++ b/Modules/Core/Common/include/itkEnableIf.h @@ -17,154 +17,7 @@ *=========================================================================*/ #ifndef itkEnableIf_h #define itkEnableIf_h - -#include "itkMacro.h" - -#if !defined(ITK_LEGACY_REMOVE) - -namespace itk -{ -/// \cond HIDE_META_PROGRAMMING -namespace mpl -{ - -/** \brief This is an implementation of the enable if idiom. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - * - * Enable if is a common C++ meta-programming technique for example - * there is a boost implementation, for more information on its usage - * please see: - * https://www.boost.org/doc/libs/1_49_0/libs/utility/enable_if.html - * - * This template enables specialization of a templated function based - * on some traits or concepts. It is implemented with SFINAE. - * - * If the parameter V is true then the Type trait is the second - * template parameter, otherwise an implementation does not exist and - * with SFINAE another implementation may be chosen. - * - * Example: - \code - template< typename TType> - typename EnableIfC< - IsSame::ValueType>::Value, - TType >::Type - GetComponent(const TType pix, - unsigned int itkNotUsed( idx ) ) const - { - return pix; - } - \endcode - * - * \sa \c EnableIf - */ -template -struct EnableIfC -{}; -/// \cond SPECIALIZATION_IMPLEMENTATION -template -struct EnableIfC -{ - using Type = TType; -}; -/// \endcond - - -/** \brief An implementation of the negation of the enable if idiom. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - * - * \sa \c EnableIfC - * \sa \c DisableIf - */ -template -struct DisableIfC -{}; -/// \cond SPECIALIZATION_IMPLEMENTATION -template -struct DisableIfC -{ - using Type = TType; -}; -/// \endcond - -/** \brief simplified way to dispose of \c enable_if. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - * \tparam TCondition Condition type. It's expected to provide a boolean value - * through its \c Value member. - * \tparam TType Type to \em return when the \c TCondition is (a) true (type). - * - * This \em overload automatically fetches \c TCondition value. However, beware, it - * won't work with standard C++ traits or boost traits. Indeed, this \c - * enable_if overload expects the \em value to follow UpperCamelCase ITK naming - * policy instead of the standard snake_case policy. - * - * Example: - \code - template< typename TType> - typename EnableIf< - IsSame::ValueType>, - TType >::Type - GetComponent(const TType pix, - unsigned int itkNotUsed( idx ) ) const - { - return pix; - } - \endcode - * \sa \c EnableIfC - * \sa \c DisableIf - */ -template -struct EnableIf : public EnableIfC -{}; - -/** \brief simplified way to dispose of \c disable_if. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - * \tparam TCondition Condition type. It's expected to provide a boolean value - * through its \c Value member. - * \tparam TType Type to \em return when the \c TCondition is (a) false (type). - * - * This \em overload automatically fetches \c TCondition value. However, beware, it - * won't work with standard C++ traits or boost traits. Indeed, this \c - * enable_if overload expects the \em value to follow UpperCamelCase ITK naming - * policy instead of the standard snake_case policy. - * - * Example: - \code - template< typename TType> - typename DisableIf< - mpl::Not_::ValueType>>, - TType >::Type - GetComponent(const TType pix, - unsigned int itkNotUsed( idx ) ) const - { - return pix; - } - \endcode - * \sa \c EnableIfC - * \sa \c DisableIf - */ -template -struct DisableIf : public DisableIfC -{}; - -} // namespace mpl - -// itk::EnableIf(C), DisableIf(C) have move to itk::mpl -// Expect them to be deprecated. -using mpl::EnableIf; -using mpl::DisableIf; -using mpl::EnableIfC; -using mpl::DisableIfC; - -/// \endcond -} // namespace itk - -#else // ITK_LEGACY_REMOVE -# error Use C++ 11 std::enable_if directly -#endif +// This file is no longer needed, features are natively available in C++11 +#error Use C++ 11 std::enable_if directly #endif // itkEnableIf_h diff --git a/Modules/Core/Common/include/itkIsBaseOf.h b/Modules/Core/Common/include/itkIsBaseOf.h index 34cc34b6129..6882791877b 100644 --- a/Modules/Core/Common/include/itkIsBaseOf.h +++ b/Modules/Core/Common/include/itkIsBaseOf.h @@ -18,39 +18,6 @@ #ifndef itkIsBaseOf_h #define itkIsBaseOf_h -#include - -#include "itkMacro.h" - -#if !defined(ITK_LEGACY_REMOVE) - -namespace itk -{ -/// \cond HIDE_META_PROGRAMMING -namespace mpl -{ -/** Traits that emulates \c std::is_base_of<>. - * \tparam TBase base type - * \tparam TDerived derived type - * \return (in \c Value) whether \c TDerived inherits (publicly) from \c TBase - * (directly, or indirectly) - * \author The definition provided follows the code snippet available in Andrei - * Alexandrescu's Modern C++ Design. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - */ -template -struct IsBaseOf -{ - static constexpr bool Value = std::is_base_of_v; -}; -} // end namespace mpl - -/// \endcond -} // end namespace itk - -#else // ITK_LEGACY_REMOVE -# error Use C++ 11 std::is_base_of directly -#endif +#error Use C++ 11 std::is_base_of directly #endif // itkIsBaseOf_h diff --git a/Modules/Core/Common/include/itkIsConvertible.h b/Modules/Core/Common/include/itkIsConvertible.h index 12193fd05b9..66c6ecffa6d 100644 --- a/Modules/Core/Common/include/itkIsConvertible.h +++ b/Modules/Core/Common/include/itkIsConvertible.h @@ -17,75 +17,7 @@ *=========================================================================*/ #ifndef itkIsConvertible_h #define itkIsConvertible_h - -#include "itkMacro.h" - -#if !defined(ITK_LEGACY_REMOVE) - -# include "itkMetaProgrammingLibrary.h" - -namespace itk -{ - -/** \cond HIDE_META_PROGRAMMING */ - -namespace mpl -{ -namespace Details -{ - -/** Helper root class for Meta-programming purpose. - * This class provides two types that help build SFINAE based meta-programs. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - */ -struct SfinaeTypes -{ - using TOne = char; - struct TTwo - { - char arr__[2]; - }; -}; -} // namespace Details - -/** Traits that emulates \c std::is_convertible<>. - * \tparam TFrom type to convert from - * \tparam TTo type to convert to - * \return (in \c Value) whether \c TFrom objects can be converted into \c TTo - * objects. - * \warning This version does not support \c void, function pointers, nor arrays. - * \author The definition provided follows the code snippet available in Andrei - * Alexandrescu's Modern C++ Design. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - */ -template -struct IsConvertible : private Details::SfinaeTypes -{ -private: - static TOne Test(TTo); - static TTwo - Test(...); - static TFrom - MakeT(); - -public: - static constexpr bool Value = sizeof(Test(MakeT())) == sizeof(TOne); -}; - -} // end namespace mpl - -// itk::IsConvertible has moved to itk::mpl. -// Expect itk::IsConvertible to be deprecated. -using mpl::IsConvertible; - -/** \endcond */ - -} // end namespace itk - -#else // ITK_LEGACY_REMOVE -# error Use C++ 11 std::is_convertible directly -#endif +// This file is no longer needed, C++11 provides support directly +#error Use C++ 11 std::is_convertible directly #endif // itkIsConvertible_h diff --git a/Modules/Core/Common/include/itkIsSame.h b/Modules/Core/Common/include/itkIsSame.h index 93cf498df08..fe195927b4d 100644 --- a/Modules/Core/Common/include/itkIsSame.h +++ b/Modules/Core/Common/include/itkIsSame.h @@ -18,44 +18,7 @@ #ifndef itkIsSame_h #define itkIsSame_h -#include "itkMacro.h" - -#if !defined(ITK_LEGACY_REMOVE) - -# include "itkMetaProgrammingLibrary.h" - -namespace itk -{ -/// \cond HIDE_META_PROGRAMMING -namespace mpl -{ - -/** Tells whether two types are identical. - * \ingroup MetaProgrammingLibrary - * \ingroup ITKCommon - */ -template -struct IsSame : public FalseType -{}; - -/// \cond SPECIALIZATION_IMPLEMENTATION -template -struct IsSame : public TrueType -{}; -/// \endcond - -} // end namespace mpl - -// itk::IsSame have move to itk::mpl -// Expect them to be deprecated. -using mpl::IsSame; - -/// \endcond - -} // end namespace itk - -#else // ITK_LEGACY_REMOVE -# error Use C++ 11 std::is_same directly -#endif +// This file is no longer needed, C++11 provides support directly +#error Use C++ 11 std::is_same directly #endif // itkIsSame_h diff --git a/Modules/Core/Common/include/itkStaticAssert.h b/Modules/Core/Common/include/itkStaticAssert.h index 83fbbda022c..f93c2b42db9 100644 --- a/Modules/Core/Common/include/itkStaticAssert.h +++ b/Modules/Core/Common/include/itkStaticAssert.h @@ -19,19 +19,8 @@ #ifndef itkStaticAssert_h #define itkStaticAssert_h -#include "itkMacro.h" - -#if !defined(ITK_LEGACY_REMOVE) -/** Static assertion. - * This macro will use C++11 \c static_assert() keyword. - * \param expr compile-time expression to check - * \param str string literal that will appear as compiler error if \c expr is \c false. - * \ingroup ITKCommon - */ -# define itkStaticAssert(expr, str) static_assert(expr, str) -#else -# define itkStaticAssert(expr, str) Use C++ 11 static_assert directly -#endif +// This is no longer needed as C++11 provides this support directly +#define itkStaticAssert(expr, str) static_assert(false, "Use C++ 11 static_assert directly") // TODO: remove this file entirely in the future (e.g. with ITKv6)