Modernize syntax of enable_if and traits to use _t helpers
authorKevin Boyd <kevin.boyd@uconn.edu>
Fri, 12 Jul 2019 15:50:02 +0000 (11:50 -0400)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 23 Jul 2019 05:57:33 +0000 (07:57 +0200)
From c++ 14, "typename std::enable_if<something>::type"
can be reduced to
              "std::enable_if_t<something>"

as can traits with ::type

Note that when we switch to C++ 17, a number of traits with
::value can be similarly shorthanded with _v

Change-Id: I92d4502c51ac613fa81f130ed3127c812c4e0a6f

18 files changed:
src/gromacs/ewald/pme_gather.cpp
src/gromacs/gpu_utils/tests/hostallocator.cpp
src/gromacs/math/arrayrefwithpadding.h
src/gromacs/math/tests/arrayrefwithpadding.cpp
src/gromacs/math/vectypes.h
src/gromacs/mdspan/extensions.h
src/gromacs/mdspan/layouts.h
src/gromacs/mdspan/mdspan.h
src/gromacs/simd/simd.h
src/gromacs/simd/simd_memory.h
src/gromacs/simd/tests/simd_memory.cpp
src/gromacs/utility/allocator.h
src/gromacs/utility/any.h
src/gromacs/utility/arrayref.h
src/gromacs/utility/enumerationhelpers.h
src/gromacs/utility/exceptions.h
src/gromacs/utility/tests/arrayref.cpp
src/testutils/mpitest.h

index f9913ff0c93ddbedda067a0041ea2dddad74c70d..d4cc6772ef36fe4e79f60c4c823f3f1b8a112a87 100644 (file)
@@ -215,7 +215,7 @@ struct do_fspline
  * This code supports pme_order <= 5.
  */
     template <int Order>
-    typename std::enable_if<Order == 4 || Order == 5, RVec>::type
+    std::enable_if_t<Order == 4 || Order == 5, RVec>
     operator()(std::integral_constant<int, Order>  order) const
     {
         const int                     norder = nn*order;
index c7613dd1843b18af27af427a7ce59052793a8677..301e0940c080c45dc0a9ed1540046c1110db4c52 100644 (file)
@@ -90,7 +90,7 @@ template <typename T>
 ArrayRef<char> charArrayRefFromArray(T *data, size_t size)
 {
     // Make a type like T, but without its possible const qualifier.
-    using NonConstT = typename std::remove_const<T>::type;
+    using NonConstT = std::remove_const_t<T>;
     return arrayRefFromArray<char>(reinterpret_cast<char *>(const_cast<NonConstT *>(data)), size * sizeof(T));
 }
 
index 55fc17ad0e4ec8f136958e01f1e59b93145ead82..148eda69d3a47783af90bb87f25974ec538e1387 100644 (file)
@@ -113,9 +113,9 @@ class ArrayRefWithPadding
             : begin_(std::move(o.begin_)), end_(std::move(o.end_)), paddedEnd_(std::move(o.paddedEnd_)) {}
         //! Convenience overload constructor to make an ArrayRefWithPadding<const T> from a non-const one.
         template<typename U,
-                 typename = typename std::enable_if<
+                 typename = std::enable_if_t<
                          std::is_same<value_type,
-                                      const typename std::remove_reference<U>::type::value_type>::value>::type>
+                                      const typename std::remove_reference_t<U>::value_type>::value> >
         ArrayRefWithPadding(U &&o)
         {
             auto constArrayRefWithPadding = o.constArrayRefWithPadding();
index eea18884dcaa01aec8f01ff7c7698e0b1cc8ab7e..e3774a476fa1db18a37bda9b6c080460e8f2bd8b 100644 (file)
@@ -183,7 +183,7 @@ TYPED_TEST(ArrayRefWithPaddingTest, ConstructFromPointersWorks)
 }
 
 template<bool c, typename T>
-using makeConstIf_t = typename std::conditional<c, const T, T>::type;
+using makeConstIf_t = std::conditional_t<c, const T, T>;
 
 //! Helper struct for the case actually used in mdrun signalling
 template <typename T>
index 40f129bd29905cbfa92f520e46e17e2b19a492cf..e03d0bf35f567bd0dfb30c4f584e6c2cf4c63648 100644 (file)
@@ -93,7 +93,7 @@ class BasicVector
         // of pointers, the implementation will be different enough that the whole
         // template class should have a separate partial specialization. We try to avoid
         // accidental matching to pointers, but this assertion is a no-cost extra check.
-        static_assert(!std::is_pointer<typename std::remove_cv<ValueType>::type>::value,
+        static_assert(!std::is_pointer < std::remove_cv_t < ValueType>>::value,
                       "BasicVector value type must not be a pointer.");
 
         //! Constructs default (uninitialized) vector.
index 20163f495413aa296bea214e1f2b562714675f04..4b774151645ae620170230c6224b61ad09dc2775 100644 (file)
@@ -59,8 +59,8 @@ namespace gmx
  *       the view itself, so a single begin that takes a const view suffices.
  */
 template <class BasicMdspan>
-constexpr typename std::enable_if<BasicMdspan::is_always_contiguous(),
-                                  typename BasicMdspan::pointer>::type
+constexpr std::enable_if_t<BasicMdspan::is_always_contiguous(),
+                           typename BasicMdspan::pointer>
 begin(const BasicMdspan &basicMdspan)
 {
     return basicMdspan.data();
@@ -73,8 +73,8 @@ begin(const BasicMdspan &basicMdspan)
  *       the view itself, so a single end that takes a const view suffices.
  */
 template <class BasicMdspan>
-constexpr typename std::enable_if<BasicMdspan::is_always_contiguous(),
-                                  typename BasicMdspan::pointer>::type
+constexpr std::enable_if_t<BasicMdspan::is_always_contiguous(),
+                           typename BasicMdspan::pointer>
 end(const BasicMdspan &basicMdspan)
 {
     return basicMdspan.data() + basicMdspan.mapping().required_span_size();
index 4e1cda739dde4949e6a259ac44787177a5d7cdaf..0b6d073c9e4cad31c7f800d55528963a7a0a143b 100644 (file)
@@ -186,7 +186,7 @@ class layout_right
                  * \returns One-dimensional integer index.
                  */
                 template<class ... Indices >
-                typename std::enable_if<sizeof ... (Indices) == Extents::rank(), index_type>::type
+                std::enable_if_t<sizeof ... (Indices) == Extents::rank(), index_type>
                 constexpr operator()( Indices ... indices ) const noexcept
                 { return offset( 0, 0, indices ... ); }
 
index 88bd55f6c9d77750c84b5ab68099b851a58e10a3..2f2465181f4473c4266c360de86f13d8181aec33 100644 (file)
@@ -121,7 +121,7 @@ class basic_mdspan
         //! Exposes the type of stored element.
         using element_type     = typename accessor_type::element_type;
         //! Expose the underlying type of the stored elements.
-        using value_type       = typename std::remove_cv<element_type>::type;
+        using value_type       = std::remove_cv_t<element_type>;
         //! Expose the type used for indexing.
         using index_type       = ptrdiff_t;
         //! Expose type for index differences.
@@ -207,9 +207,9 @@ class basic_mdspan
          * \param[in] other mdspan-implementing container
          */
         template<typename U,
-                 typename = typename std::enable_if<
-                         std::is_same<typename std::remove_reference<U>::type::view_type::element_type,
-                                      ElementType>::value>::type>
+                 typename = std::enable_if_t<
+                         std::is_same<typename std::remove_reference_t<U>::view_type::element_type,
+                                      ElementType>::value> >
         constexpr basic_mdspan(U &&other) : basic_mdspan(other.asView()) {}
         /*! \brief Construct mdspan of const Elements from multidimensional arrays implemented with mdspan
          *
@@ -222,9 +222,9 @@ class basic_mdspan
          * \param[in] other mdspan-implementing container
          */
         template<typename U,
-                 typename = typename std::enable_if<
-                         std::is_same<typename std::remove_reference<U>::type::const_view_type::element_type,
-                                      ElementType>::value>::type>
+                 typename = std::enable_if_t<
+                         std::is_same<typename std::remove_reference_t<U>::const_view_type::element_type,
+                                      ElementType>::value> >
         constexpr basic_mdspan(const U &other) : basic_mdspan(other.asConstView()) {}
         /*! \brief Brace operator to access multidimensional array element.
          * \param[in] indices The multidimensional indices of the object.
@@ -232,7 +232,7 @@ class basic_mdspan
          * \returns reference to element at indices.
          */
         template<class... IndexType >
-        constexpr typename std::enable_if<sizeof ... (IndexType) == extents_type::rank(), reference>::type
+        constexpr std::enable_if_t<sizeof ... (IndexType) == extents_type::rank(), reference>
         operator()( IndexType... indices) const noexcept
         { return acc_.access( ptr_, map_( indices ... ) ); }
         /*! \brief Canonical bracket operator for one-dimensional arrays.
@@ -242,8 +242,8 @@ class basic_mdspan
          * \returns reference to element stored at position i
          */
         template<class IndexType>
-        constexpr typename std::enable_if<std::is_integral<IndexType>::value &&
-                                          extents_type::rank() == 1, reference>::type
+        constexpr std::enable_if_t<std::is_integral<IndexType>::value &&
+                                   extents_type::rank() == 1, reference>
         operator[]( const IndexType &i ) const noexcept
         { return acc_.access( ptr_, map_(i) ); }
         /*! \brief Bracket operator for multi-dimensional arrays.
index 51bb2da4bd1c282151259cdaa4dd4e4a12903069..04b7997aa5e09a3d25edab18b004406f3a31f500 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -495,7 +495,7 @@ static inline T
  * 2) load(real*); template parameter is mandatory because otherwise ambiguity is
  *    created. The dependent type disables type deduction.
  */
-load(const typename std::enable_if<std::is_arithmetic<T>::value, T>::type *m)
+load(const std::enable_if_t<std::is_arithmetic<T>::value, T> *m)
 {
     return *m;
 }
@@ -522,7 +522,7 @@ loadU(const typename internal::SimdTraits<T>::type *m)
 
 template<typename T>
 static inline T
-loadU(const typename std::enable_if<std::is_arithmetic<T>::value, T>::type *m)
+loadU(const std::enable_if_t<std::is_arithmetic<T>::value, T> *m)
 {
     return *m;
 }
index 750c391bc35dc9f4bb18af758222a0d0b771106d..089072cb04de92b8930270564c8a6714f2c84dfb 100644 (file)
@@ -54,7 +54,7 @@ template<typename T>
 class SimdReference
 {
     private:
-        using non_const_T = typename std::remove_const<T>::type;
+        using non_const_T = std::remove_const_t<T>;
         using pointer     = typename SimdTraits<T>::type*;
     public:
         //! \brief Constructor
@@ -204,9 +204,9 @@ class SimdArrayRef
         }
         //! \copydoc ArrayRef::ArrayRef(U)
         template<typename U,
-                 typename = typename std::enable_if<
-                         std::is_convertible<typename std::remove_reference<U>::type::pointer,
-                                             pointer>::value>::type>
+                 typename = std::enable_if_t<
+                         std::is_convertible<typename std::remove_reference_t<U>::pointer,
+                                             pointer>::value> >
         SimdArrayRef(U &&o) : begin_(reinterpret_cast<pointer>(o.data())),
                               end_(reinterpret_cast<pointer>(o.data()+o.size())) {}
         //reinterpret_cast is only needed for const conversion of SimdArrayRef itself.
index 007cdd5ccee75fa87b1fa735bf0644470eee7091..7e08b2fb255b6a89bea6e8763d81d33c116122e5 100644 (file)
@@ -97,7 +97,7 @@ class ArrayRefTest : public test::SimdTest
         using ArrayRefType = TypeParam;
         using PointerType  = typename ArrayRefType::pointer;
         using ValueType    = typename ArrayRefType::value_type;
-        using ElementType  = typename std::remove_const<typename gmx::internal::SimdTraits<ValueType>::type>::type;
+        using ElementType  = std::remove_const_t < typename gmx::internal::SimdTraits < ValueType>::type>;
         static constexpr int width = gmx::internal::SimdTraits<ValueType>::width;
 
         /*! \brief Run the same tests all the time
@@ -165,7 +165,7 @@ TYPED_TEST(ArrayRefTest, ConstructFromArrayRefWorks)
     std::array<typename TestFixture::ElementType, TestFixture::width*3> a;
 
     std::iota(a.begin(), a.end(), 0);
-    ArrayRef<typename std::remove_const<typename TestFixture::ValueType>::type>
+    ArrayRef < std::remove_const_t < typename TestFixture::ValueType>>
     ref(a.data(), a.data()+a.size());
     typename TestFixture::ArrayRefType        arrayRef(ref);
     this->runReadOnlyTests(a.data(), 3, arrayRef);
index f888583d99305917e098c29f21470f3759352949..c292a154bfb3d2f2ffa3bc4f16bfcb0304e63eee 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -159,7 +159,7 @@ class Allocator : public AllocationPolicy
          * FUTURE: Can be removed with C++17 (is_always_equal)
          */
         template<class T2, class A = AllocationPolicy,
-                 typename          = typename std::enable_if<std::is_empty<A>::value>::type>
+                 typename          = std::enable_if_t<std::is_empty<A>::value> >
         bool operator==(const Allocator<T2, AllocationPolicy> & /*unused*/) const { return true; }
 
         /*! \brief Return true if two allocators are different
index 8e9464e4227e1f73f1e0960befcb58fe3a22b5c8..30e4a732f34c2cc55d4fb74962c88860399e2a57 100644 (file)
@@ -106,9 +106,9 @@ class Any
          *
          * \throws std::bad_alloc if out of memory.
          */
-        template <typename T, typename = typename std::enable_if<!std::is_same<T, Any>::value>::type>
+        template <typename T, typename = std::enable_if_t<!std::is_same<T, Any>::value> >
         explicit Any(T &&value)
-            : content_(new Content<typename std::decay<T>::type>(std::forward<T>(value)))
+            : content_(new Content < std::decay_t < T>>(std::forward<T>(value)))
         {
         }
         /*! \brief
index ba2c041ab04ee69309c2d021511c97c95e8ba511..ac7a8a0c7dd3f21bc22253fa30563a5b157b34c9 100644 (file)
@@ -146,9 +146,9 @@ class ArrayRef
          * a container to a method that takes ArrayRef.
          */
         template<typename U,
-                 typename = typename std::enable_if<
-                         std::is_convertible<typename std::remove_reference<U>::type::pointer,
-                                             pointer>::value>::type>
+                 typename = std::enable_if_t<
+                         std::is_convertible<typename std::remove_reference_t<U>::pointer,
+                                             pointer>::value> >
         ArrayRef(U &&o) : begin_(o.data()), end_(o.data()+o.size()) {}
         /*! \brief
          * Constructs a reference to a particular range.
@@ -273,9 +273,9 @@ ArrayRef<const T> constArrayRefFromArray(const T *begin, size_t size)
  * \see ArrayRef
  */
 template <typename T>
-ArrayRef<typename std::conditional<std::is_const<T>::value,
-                                   const typename T::value_type,
-                                   typename T::value_type>::type>
+ArrayRef < std::conditional_t < std::is_const<T>::value,
+const typename T::value_type,
+typename T::value_type>>
 makeArrayRef(T &c)
 {
     return c;
index 49ecd98d9c0c2da0039dabfb32cb71400d2336eb..20f11e908b04ed20366221ea24fed45d276b5524 100644 (file)
@@ -113,7 +113,7 @@ class EnumerationIterator final
 {
     public:
         //! Convenience alias
-        using IntegerType = typename std::underlying_type<EnumType>::type;
+        using IntegerType = std::underlying_type_t<EnumType>;
 
         /*! \name Iterator type traits
          * Satisfies the requirements for STL forward iterator.
index 8b45e82abcb97e6d36e8ffce4b70bf6b401c45b1..053ba3b573595a92c2fb99db570cf1cdfc7f609e 100644 (file)
@@ -389,7 +389,7 @@ class GromacsException : public std::exception
  */
 template <class Exception, class Tag, class T>
 inline
-typename std::enable_if<std::is_base_of<GromacsException, Exception>::value, Exception>::type
+std::enable_if_t<std::is_base_of<GromacsException, Exception>::value, Exception>
 operator<<(Exception ex, const ExceptionInfo<Tag, T> &item)
 {
     ex.setInfo(item);
index e8a8388f862b8897813af1a72ac54743aab8b4c2..6cdb84b0585403cafffd4127fe43ee4f98beecfc 100644 (file)
@@ -109,7 +109,7 @@ class ArrayRefTest : public ::testing::Test
     public:
         typedef TypeParam ArrayRefType;
         typedef typename ArrayRefType::value_type ValueType;
-        typedef typename std::remove_const<ValueType>::type NonConstValueType;
+        typedef std::remove_const_t<ValueType> NonConstValueType;
 
         /*! \brief Run the same tests all the time
          *
@@ -174,7 +174,7 @@ TYPED_TEST(ArrayRefTest, ConstructFromNonConstPointersWorks)
 }
 
 template<bool c, typename T>
-using makeConstIf_t = typename std::conditional<c, const T, T>::type;
+using makeConstIf_t = std::conditional_t<c, const T, T>;
 
 TYPED_TEST(ArrayRefTest, ConstructFromVectorWorks)
 {
index 20629fd516df9c08d657481c41993a80a9605b4e..d4eababfca28d8bd00ca23681024baf3559c1a8c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -114,7 +114,7 @@ bool threadMpiTestRunner(std::function<void()> testBody);
 #define GMX_MPI_TEST(expectedRankCount) \
     do { \
         ASSERT_EQ(expectedRankCount, ::gmx::test::getNumberOfTestMpiRanks()); \
-        typedef std::remove_reference<decltype(*this)>::type MyTestClass; \
+        using MyTestClass = std::remove_reference_t<decltype(*this)>; \
         if (!::gmx::test::threadMpiTestRunner(std::bind(&MyTestClass::TestBody, this))) \
         { \
             return; \