From 2f876de263efdf08daf160e7791434cd760ccd9b Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Mon, 6 Jul 2020 14:19:37 +0000 Subject: [PATCH] Modernize STL usage --- src/gromacs/compat/pointers.h | 16 +++--- src/gromacs/compat/utility.h | 57 ------------------- src/gromacs/domdec/hashedmap.h | 6 +- src/gromacs/domdec/localatomsetdata.h | 2 +- src/gromacs/domdec/localatomsetmanager.h | 2 +- src/gromacs/ewald/pme_gather.cpp | 2 +- src/gromacs/fileio/mrcserializer.cpp | 8 +-- .../fileio/tests/fileioxdrserializer.cpp | 2 +- src/gromacs/gpu_utils/oclutils.h | 9 ++- src/gromacs/math/arrayrefwithpadding.h | 4 +- src/gromacs/math/paddedvector.h | 6 +- src/gromacs/math/tests/testarrayrefs.h | 2 +- src/gromacs/math/vectypes.h | 2 +- src/gromacs/mdspan/mdspan.h | 12 ++-- src/gromacs/random/uniformrealdistribution.h | 3 +- src/gromacs/simd/simd.h | 24 ++++---- src/gromacs/simd/simd_memory.h | 10 ++-- src/gromacs/simd/tests/simd_memory.cpp | 10 ++-- src/gromacs/utility/allocator.h | 4 +- src/gromacs/utility/any.h | 4 +- src/gromacs/utility/arrayref.h | 6 +- .../utility/defaultinitializationallocator.h | 4 +- src/gromacs/utility/exceptions.h | 2 +- src/gromacs/utility/fixedcapacityvector.h | 4 +- src/gromacs/utility/listoflists.h | 6 +- src/gromacs/utility/range.h | 2 +- src/gromacs/utility/smalloc.h | 13 ++--- src/gromacs/utility/tests/arrayref.cpp | 4 +- .../utility/tests/inmemoryserializer.cpp | 14 ++--- 29 files changed, 90 insertions(+), 150 deletions(-) delete mode 100644 src/gromacs/compat/utility.h diff --git a/src/gromacs/compat/pointers.h b/src/gromacs/compat/pointers.h index ac3099207e..f10760581f 100644 --- a/src/gromacs/compat/pointers.h +++ b/src/gromacs/compat/pointers.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -89,24 +89,24 @@ template class not_null { public: - static_assert(std::is_assignable::value, "T cannot be assigned nullptr."); + static_assert(std::is_assignable_v, "T cannot be assigned nullptr."); //! Move constructor. Asserts in debug mode if \c is nullptr. - template::value>::type> + template>> constexpr explicit not_null(U&& u) : ptr_(std::forward(u)) { Expects(ptr_ != nullptr); } //! Simple constructor. Asserts in debug mode if \c u is nullptr. - template::value>::type> + template>> constexpr explicit not_null(T u) : ptr_(u) { Expects(ptr_ != nullptr); } //! Copy constructor. - template::value>::type> + template>> constexpr not_null(const not_null& other) : not_null(other.get()) { } @@ -155,16 +155,14 @@ private: template not_null make_not_null(T&& t) { - return not_null::type>::type>{ - std::forward(t) - }; + return not_null>>{ std::forward(t) }; } //! Convenience function for making not_null pointers from smart pointers. template not_null make_not_null(T& t) { - return not_null::type::pointer>{ t.get() }; + return not_null::pointer>{ t.get() }; } //! Operators to compare not_null pointers. diff --git a/src/gromacs/compat/utility.h b/src/gromacs/compat/utility.h deleted file mode 100644 index c3fcdc6c5f..0000000000 --- a/src/gromacs/compat/utility.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of the GROMACS molecular simulation package. - * - * Copyright (c) 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. - * - * GROMACS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * GROMACS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with GROMACS; if not, see - * http://www.gnu.org/licenses, or write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * If you want to redistribute modifications to GROMACS, please - * consider that scientific software is very special. Version - * control is crucial - bugs must be traceable. We will be happy to - * consider code for inclusion in the official distribution, but - * derived work must not be called official GROMACS. Details are found - * in the README & COPYING files - if they are missing, get the - * official version at http://www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the research papers on the package. Check out http://www.gromacs.org. - */ - -/*! \libinternal \file - * \brief Provides backported functions/classes from utility - * - * \author Roland Schulz - * \ingroup module_compat - * \inlibraryapi - */ -#ifndef GMX_COMPAT_UTILITY_H -#define GMX_COMPAT_UTILITY_H -namespace gmx -{ -namespace compat -{ -//! Forms lvalue reference to const type of t -template -constexpr const T& as_const(T& t) noexcept -{ - return t; -} -} // namespace compat -} // namespace gmx -#endif diff --git a/src/gromacs/domdec/hashedmap.h b/src/gromacs/domdec/hashedmap.h index 32bc3ceb25..4ef845b601 100644 --- a/src/gromacs/domdec/hashedmap.h +++ b/src/gromacs/domdec/hashedmap.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -50,9 +50,9 @@ #include #include +#include #include -#include "gromacs/compat/utility.h" #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/exceptions.h" @@ -260,7 +260,7 @@ public: * \param[in] key The key * \return a pointer to value for the given key or nullptr when not present */ - T* find(int key) { return const_cast(gmx::compat::as_const(*this).find(key)); } + T* find(int key) { return const_cast(std::as_const(*this).find(key)); } /*! \brief Returns a pointer to the value for the given key or nullptr when not present * diff --git a/src/gromacs/domdec/localatomsetdata.h b/src/gromacs/domdec/localatomsetdata.h index 89cb5216fe..a41c6dceef 100644 --- a/src/gromacs/domdec/localatomsetdata.h +++ b/src/gromacs/domdec/localatomsetdata.h @@ -75,7 +75,7 @@ public: * * \param[in] globalAtomIndex Indices of the atoms to be managed */ - template::value, T>> + template, T>> explicit LocalAtomSetData(ArrayRef globalAtomIndex) : globalIndex_(globalAtomIndex.begin(), globalAtomIndex.end()), localIndex_(globalAtomIndex.begin(), globalAtomIndex.end()) diff --git a/src/gromacs/domdec/localatomsetmanager.h b/src/gromacs/domdec/localatomsetmanager.h index 8a2c227f32..bff8519745 100644 --- a/src/gromacs/domdec/localatomsetmanager.h +++ b/src/gromacs/domdec/localatomsetmanager.h @@ -84,7 +84,7 @@ public: * \param[in] globalAtomIndex Indices of the atoms to be managed * \returns Handle to LocalAtomSet. */ - template::value, T>> + template, T>> LocalAtomSet add(ArrayRef globalAtomIndex); #endif /*! \brief Add a new atom set to be managed and give back a handle. diff --git a/src/gromacs/ewald/pme_gather.cpp b/src/gromacs/ewald/pme_gather.cpp index 41d8f3a783..2a7925cfe2 100644 --- a/src/gromacs/ewald/pme_gather.cpp +++ b/src/gromacs/ewald/pme_gather.cpp @@ -93,7 +93,7 @@ struct do_fspline template RVec operator()(Int order) const { - static_assert(isIntegralConstant::value || std::is_same::value, + static_assert(isIntegralConstant::value || std::is_same_v, "'order' needs to be either of type integral_constant or int."); const int norder = nn * order; diff --git a/src/gromacs/fileio/mrcserializer.cpp b/src/gromacs/fileio/mrcserializer.cpp index ac4968cdf2..96899c0389 100644 --- a/src/gromacs/fileio/mrcserializer.cpp +++ b/src/gromacs/fileio/mrcserializer.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,2020, 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. @@ -77,7 +77,7 @@ enum class MachineStamp : int32_t * \param[in,out] valueContainer the array to be serialized */ template -std::enable_if_t::value, void> +std::enable_if_t, void> serialize(ISerializer* serializer, ContainerType* valueContainer) { for (auto& value : *valueContainer) @@ -95,7 +95,7 @@ serialize(ISerializer* serializer, ContainerType* valueContainer) * \param[in,out] valueContainer the array to be serialized */ template -std::enable_if_t::value, void> +std::enable_if_t, void> serialize(ISerializer* serializer, ContainerType* valueContainer) { for (auto& value : *valueContainer) @@ -134,7 +134,7 @@ void serializeIndices(ISerializer* serializer, std::array* valueArra * \tparam IntegralType type to be serialized as int32_t */ template -std::enable_if_t<(std::is_integral::value || std::is_enum::value), void> +std::enable_if_t<(std::is_integral_v || std::is_enum_v), void> serializeAsInt32(ISerializer* serializer, IntegralType* value) { int32_t serializedValue; diff --git a/src/gromacs/fileio/tests/fileioxdrserializer.cpp b/src/gromacs/fileio/tests/fileioxdrserializer.cpp index fb4dcf5af0..2c5d9b0c43 100644 --- a/src/gromacs/fileio/tests/fileioxdrserializer.cpp +++ b/src/gromacs/fileio/tests/fileioxdrserializer.cpp @@ -103,7 +103,7 @@ public: std::int64_t int64Value_ = c_int64Value; double doubleValue_ = c_intAndFloat64.doubleValue_; int intValue_ = integerSizeDependentTestingValue(); - real realValue_ = std::is_same::value + real realValue_ = std::is_same_v ? static_cast(c_intAndFloat64.doubleValue_) : static_cast(c_intAndFloat32.floatValue_); } defaultValues_; diff --git a/src/gromacs/gpu_utils/oclutils.h b/src/gromacs/gpu_utils/oclutils.h index 333147d78f..bb776d4781 100644 --- a/src/gromacs/gpu_utils/oclutils.h +++ b/src/gromacs/gpu_utils/oclutils.h @@ -149,11 +149,10 @@ void prepareGpuKernelArgument(cl_kernel kernel, // Assert on types not allowed to be passed to a kernel // (as per section 6.9 of the OpenCL spec). - static_assert(!std::is_same::value && !std::is_same::value - && !std::is_same::value - && !std::is_same::value - && !std::is_same::value, - "Invalid type passed to OpenCL kernel functions (see OpenCL spec section 6.9)."); + static_assert( + !std::is_same_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && !std::is_same_v, + "Invalid type passed to OpenCL kernel functions (see OpenCL spec section 6.9)."); prepareGpuKernelArgument(kernel, config, argIndex + 1, otherArgsPtrs...); } diff --git a/src/gromacs/math/arrayrefwithpadding.h b/src/gromacs/math/arrayrefwithpadding.h index 3e5f535c6c..7a8a2b632f 100644 --- a/src/gromacs/math/arrayrefwithpadding.h +++ b/src/gromacs/math/arrayrefwithpadding.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -121,7 +121,7 @@ public: { } //! Convenience overload constructor to make an ArrayRefWithPadding from a non-const one. - template::value_type>::value>> + template::value_type>>> ArrayRefWithPadding(U&& o) { auto constArrayRefWithPadding = o.constArrayRefWithPadding(); diff --git a/src/gromacs/math/paddedvector.h b/src/gromacs/math/paddedvector.h index 79e5c1b08b..6a1d2e12b2 100644 --- a/src/gromacs/math/paddedvector.h +++ b/src/gromacs/math/paddedvector.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2016,2017,2018,2019,2020, 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. @@ -373,13 +373,13 @@ public: return ArrayRefWithPadding(data(), data() + size(), data() + paddedSize()); } //! Returns an rvec * pointer for containers of RVec, for use with legacy code. - template::value>> + template>> rvec* rvec_array() { return as_rvec_array(data()); } //! Returns a const rvec * pointer for containers of RVec, for use with legacy code. - template::value>> + template>> const rvec* rvec_array() const { return as_rvec_array(data()); diff --git a/src/gromacs/math/tests/testarrayrefs.h b/src/gromacs/math/tests/testarrayrefs.h index 405aa4108b..bdaae01d68 100644 --- a/src/gromacs/math/tests/testarrayrefs.h +++ b/src/gromacs/math/tests/testarrayrefs.h @@ -102,7 +102,7 @@ void compareViews(ArrayRef input, ArrayRef output) //! Comparison for non-BasicVector ignoring const qualifiers template -typename std::enable_if::type, typename std::remove_const::type>::value, void>::type +typename std::enable_if_t, std::remove_const_t>, void> compareViewsIgnoreConst(ArrayRef input, ArrayRef output) { ASSERT_EQ(input.size(), output.size()); diff --git a/src/gromacs/math/vectypes.h b/src/gromacs/math/vectypes.h index a8c49149b0..a4f3fe25a0 100644 --- a/src/gromacs/math/vectypes.h +++ b/src/gromacs/math/vectypes.h @@ -94,7 +94,7 @@ public: // 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>::value, + static_assert(!std::is_pointer_v>, "BasicVector value type must not be a pointer."); //! Constructs default (uninitialized) vector. diff --git a/src/gromacs/mdspan/mdspan.h b/src/gromacs/mdspan/mdspan.h index 10499d655d..5b2f535197 100644 --- a/src/gromacs/mdspan/mdspan.h +++ b/src/gromacs/mdspan/mdspan.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -216,7 +216,7 @@ public: * \tparam U container type * \param[in] other mdspan-implementing container */ - template::view_type::element_type, ElementType>::value>> + template::view_type::element_type, ElementType>>> constexpr basic_mdspan(U&& other) : basic_mdspan(other.asView()) { } @@ -230,7 +230,7 @@ public: * \tparam U container type * \param[in] other mdspan-implementing container */ - template::const_view_type::element_type, ElementType>::value>> + template::const_view_type::element_type, ElementType>>> constexpr basic_mdspan(const U& other) : basic_mdspan(other.asConstView()) { } @@ -252,7 +252,7 @@ public: * \returns reference to element stored at position i */ template - constexpr std::enable_if_t::value && extents_type::rank() == 1, reference> + constexpr std::enable_if_t && extents_type::rank() == 1, reference> operator[](const IndexType& i) const noexcept { return acc_.access(ptr_, map_(i)); @@ -279,8 +279,8 @@ public: */ template> - constexpr std::enable_if_t::value && (extents_type::rank() > 1) - && std::is_same::value, + constexpr std::enable_if_t && (extents_type::rank() > 1) + && std::is_same_v, sliced_mdspan_type> operator[](const IndexType index) const noexcept { diff --git a/src/gromacs/random/uniformrealdistribution.h b/src/gromacs/random/uniformrealdistribution.h index bdaf090018..17a1e9240f 100644 --- a/src/gromacs/random/uniformrealdistribution.h +++ b/src/gromacs/random/uniformrealdistribution.h @@ -113,8 +113,7 @@ RealType generateCanonical(Rng& g) // Only unsigned integer types can express the range using the // same type. Converting to RealType before computing the range // would work but we have no need for that. - static_assert(std::is_unsigned::value - && std::is_unsigned::value, + static_assert(std::is_unsigned_v && std::is_unsigned_v, "Rng::max and Rng::min must be unsigned"); RealType r = RealType(Rng::max() - Rng::min()) + RealType(1); RealType s = g() - Rng::min(); diff --git a/src/gromacs/simd/simd.h b/src/gromacs/simd/simd.h index 537046645a..d67ce0bbab 100644 --- a/src/gromacs/simd/simd.h +++ b/src/gromacs/simd/simd.h @@ -482,11 +482,12 @@ struct SimdTraits using tag = SimdDInt32Tag; }; #endif - +template +using SimdTraitsT = typename SimdTraits::type; template struct SimdTraits { - using type = const typename SimdTraits::type; + using type = const SimdTraitsT; static constexpr int width = SimdTraits::width; using tag = typename SimdTraits::tag; }; @@ -503,8 +504,7 @@ struct SimdTraits * \return Loaded value */ template -static inline std::remove_const_t -load(const typename internal::SimdTraits::type* m) // disabled by SFINAE for non-SIMD types +static inline std::remove_const_t load(const internal::SimdTraitsT* m) // disabled by SFINAE for non-SIMD types { return simdLoad(m, typename internal::SimdTraits::tag()); } @@ -516,13 +516,13 @@ static inline T * 2) load(real*); template parameter is mandatory because otherwise ambiguity is * created. The dependent type disables type deduction. */ -load(const std::enable_if_t::value, T> *m) +load(const std::enable_if_t, T> *m) { return *m; } template -static inline T gmx_simdcall load(const AlignedArray::type, N>& m) +static inline T gmx_simdcall load(const AlignedArray, N>& m) { return simdLoad(m.data(), typename internal::SimdTraits::tag()); } @@ -534,19 +534,19 @@ static inline T gmx_simdcall load(const AlignedArray -static inline T loadU(const typename internal::SimdTraits::type* m) +static inline T loadU(const internal::SimdTraitsT* m) { return simdLoadU(m, typename internal::SimdTraits::tag()); } template -static inline T loadU(const std::enable_if_t::value, T>* m) +static inline T loadU(const std::enable_if_t, T>* m) { return *m; } template -static inline T gmx_simdcall loadU(const AlignedArray::type, N>& m) +static inline T gmx_simdcall loadU(const AlignedArray, N>& m) { return simdLoadU(m.data(), typename internal::SimdTraits::tag()); } @@ -621,16 +621,18 @@ struct Simd4Traits using type = double; }; #endif +template +using Simd4TraitsT = typename Simd4Traits::type; } // namespace internal #if GMX_SIMD4_HAVE_REAL template -T load(const typename internal::Simd4Traits::type* m) +T load(const internal::Simd4TraitsT* m) { return load4(m); } template -T loadU(const typename internal::Simd4Traits::type* m) +T loadU(const internal::Simd4TraitsT* m) { return load4U(m); } diff --git a/src/gromacs/simd/simd_memory.h b/src/gromacs/simd/simd_memory.h index aa4a3c8da8..9a770ce906 100644 --- a/src/gromacs/simd/simd_memory.h +++ b/src/gromacs/simd/simd_memory.h @@ -55,7 +55,7 @@ class SimdReference { private: using non_const_T = std::remove_const_t; - using pointer = typename SimdTraits::type*; + using pointer = SimdTraitsT*; public: //! \brief Constructor @@ -98,7 +98,7 @@ class SimdIterator : using Base = boost::stl_interfaces::iterator_interface, std::random_access_iterator_tag, T, SimdReference>; // pointer is T* - using DataPointer = typename SimdTraits::type*; + using DataPointer = SimdTraitsT*; public: explicit SimdIterator(DataPointer p = 0) : p_(p) @@ -144,7 +144,7 @@ public: //! Type of values stored in the container. using value_type = T; //! Pointer to a container element. - using pointer = typename SimdTraits::type*; + using pointer = SimdTraitsT*; //! Reference to a container element. using reference = internal::SimdReference; //! Iterator type for the container. @@ -162,7 +162,7 @@ public: "Size of ArrayRef needs to be divisible by type size"); } //! \copydoc ArrayRef::ArrayRef(U) - template::pointer, pointer>::value>> + template::pointer, pointer>>> SimdArrayRef(U&& o) : begin_(reinterpret_cast(o.data())), end_(reinterpret_cast(o.data() + o.size())) @@ -190,7 +190,7 @@ public: private: static constexpr int simdWidth = SimdTraits::width; - using pack_type = typename SimdTraits::type[simdWidth]; + using pack_type = SimdTraitsT[simdWidth]; // Private because dereferencing return value is undefined behavior (strict aliasing rule) // Only use is conversion constructor above which immediately casts it back. // Return type is not "pointer" because then data()+size() would be ill defined. diff --git a/src/gromacs/simd/tests/simd_memory.cpp b/src/gromacs/simd/tests/simd_memory.cpp index b9604b49b8..22f19fc03d 100644 --- a/src/gromacs/simd/tests/simd_memory.cpp +++ b/src/gromacs/simd/tests/simd_memory.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2019, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2019,2020, 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. @@ -94,10 +94,10 @@ template class ArrayRefTest : public test::SimdTest { public: - using ArrayRefType = TypeParam; - using PointerType = typename ArrayRefType::pointer; - using ValueType = typename ArrayRefType::value_type; - using ElementType = std::remove_const_t::type>; + using ArrayRefType = TypeParam; + using PointerType = typename ArrayRefType::pointer; + using ValueType = typename ArrayRefType::value_type; + using ElementType = std::remove_const_t>; static constexpr int width = gmx::internal::SimdTraits::width; /*! \brief Run the same tests all the time diff --git a/src/gromacs/utility/allocator.h b/src/gromacs/utility/allocator.h index c4d4a23027..2bda1d6dab 100644 --- a/src/gromacs/utility/allocator.h +++ b/src/gromacs/utility/allocator.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2017,2018,2019,2020, 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. @@ -153,7 +153,7 @@ public: * Always true for stateless polcies. Has to be defined in the policy for stateful policies. * FUTURE: Can be removed with C++17 (is_always_equal) */ - template::value>> + template>> bool operator==(const Allocator& /*unused*/) const { return true; diff --git a/src/gromacs/utility/any.h b/src/gromacs/utility/any.h index 7e2c86f441..77f70a7863 100644 --- a/src/gromacs/utility/any.h +++ b/src/gromacs/utility/any.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2016,2017,2018,2019,2020, 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. @@ -112,7 +112,7 @@ public: * * \throws std::bad_alloc if out of memory. */ - template::value>> + template>> explicit Any(T&& value) : content_(new Content>(std::forward(value))) { } diff --git a/src/gromacs/utility/arrayref.h b/src/gromacs/utility/arrayref.h index d7efde7145..d70527b230 100644 --- a/src/gromacs/utility/arrayref.h +++ b/src/gromacs/utility/arrayref.h @@ -73,7 +73,7 @@ struct ArrayRefIter : // This default constructor does not initialize it_ constexpr ArrayRefIter() noexcept {} constexpr explicit ArrayRefIter(T* it) noexcept : it_(it) {} - template::value>> + template>> constexpr ArrayRefIter(ArrayRefIter> it) noexcept : it_(&*it) { } @@ -176,7 +176,7 @@ public: * This constructor is not explicit to allow directly passing * a container to a method that takes ArrayRef. */ - template::pointer, pointer>::value>> + template::pointer, pointer>>> ArrayRef(U&& o) : begin_(o.data()), end_(o.data() + o.size()) { } @@ -313,7 +313,7 @@ ArrayRef constArrayRefFromArray(const T* begin, size_t size) * \see ArrayRef */ template -ArrayRef::value, const typename T::value_type, typename T::value_type>> +ArrayRef, const typename T::value_type, typename T::value_type>> makeArrayRef(T& c) { return c; diff --git a/src/gromacs/utility/defaultinitializationallocator.h b/src/gromacs/utility/defaultinitializationallocator.h index a98dc4491d..54321b3bbb 100644 --- a/src/gromacs/utility/defaultinitializationallocator.h +++ b/src/gromacs/utility/defaultinitializationallocator.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,2020, 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. @@ -70,7 +70,7 @@ public: /*! \brief Constructs an object and default initializes */ template - void construct(U* ptr) noexcept(std::is_nothrow_default_constructible::value) + void construct(U* ptr) noexcept(std::is_nothrow_default_constructible_v) { ::new (static_cast(ptr)) U; } diff --git a/src/gromacs/utility/exceptions.h b/src/gromacs/utility/exceptions.h index 034a60b3d1..51abee1c42 100644 --- a/src/gromacs/utility/exceptions.h +++ b/src/gromacs/utility/exceptions.h @@ -379,7 +379,7 @@ private: * if the enable_if causes problems with some compilers, it can be removed. */ template -inline std::enable_if_t::value, Exception> +inline std::enable_if_t, Exception> operator<<(Exception ex, const ExceptionInfo& item) { ex.setInfo(item); diff --git a/src/gromacs/utility/fixedcapacityvector.h b/src/gromacs/utility/fixedcapacityvector.h index 03c6d79443..2767449588 100644 --- a/src/gromacs/utility/fixedcapacityvector.h +++ b/src/gromacs/utility/fixedcapacityvector.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,2020, 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. @@ -194,7 +194,7 @@ public: reference emplace_back(Args&&... args) { GMX_ASSERT(size() < capacity, "Cannot add more elements than the capacity"); - if (std::is_move_assignable::value) + if (std::is_move_assignable_v) { *end_ = std::move(T(args...)); } diff --git a/src/gromacs/utility/listoflists.h b/src/gromacs/utility/listoflists.h index 96927dc80c..e9baa98b4d 100644 --- a/src/gromacs/utility/listoflists.h +++ b/src/gromacs/utility/listoflists.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,2020, 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. @@ -77,7 +77,7 @@ namespace gmx template class ListOfLists { - static_assert(std::is_arithmetic::value, "This class is limited to arithmetic types"); + static_assert(std::is_arithmetic_v, "This class is limited to arithmetic types"); public: //! Constructs an empty list of lists @@ -133,7 +133,7 @@ public: void pushBackListOfSize(int numElements) { // With arithmetic types enforced, this assertion is always true - static_assert(std::is_default_constructible::value, + static_assert(std::is_default_constructible_v, "pushBackListOfSize should only be called with default constructable types"); elements_.resize(elements_.size() + numElements); listRanges_.push_back(int(elements_.size())); diff --git a/src/gromacs/utility/range.h b/src/gromacs/utility/range.h index 8fb2f12362..5871eb4e74 100644 --- a/src/gromacs/utility/range.h +++ b/src/gromacs/utility/range.h @@ -63,7 +63,7 @@ namespace gmx template class Range { - static_assert(std::is_integral::value, "Range can only be used with integral types"); + static_assert(std::is_integral_v, "Range can only be used with integral types"); // Note: This class has as invariant: begin_ <= end_ diff --git a/src/gromacs/utility/smalloc.h b/src/gromacs/utility/smalloc.h index bf7fa34c9c..cb9fb4a739 100644 --- a/src/gromacs/utility/smalloc.h +++ b/src/gromacs/utility/smalloc.h @@ -202,7 +202,7 @@ void save_free_aligned(const char* name, const char* file, int line, void* ptr); template static inline void gmx_snew_impl(const char* name, const char* file, int line, T*& ptr, size_t nelem) { - static_assert(std::is_pod::value, "snew() called on C++ type"); + static_assert(std::is_pod_v, "snew() called on C++ type"); // NOLINTNEXTLINE bugprone-sizeof-expression ptr = static_cast(save_calloc(name, file, line, nelem, sizeof(T))); } @@ -210,7 +210,7 @@ static inline void gmx_snew_impl(const char* name, const char* file, int line, T template static inline void gmx_srenew_impl(const char* name, const char* file, int line, T*& ptr, size_t nelem) { - static_assert(std::is_pod::value, "srenew() called on C++ type"); + static_assert(std::is_pod_v, "srenew() called on C++ type"); // NOLINTNEXTLINE bugprone-sizeof-expression ptr = static_cast(save_realloc(name, file, line, ptr, nelem, sizeof(T))); } @@ -218,7 +218,7 @@ static inline void gmx_srenew_impl(const char* name, const char* file, int line, template static inline void gmx_smalloc_impl(const char* name, const char* file, int line, T*& ptr, size_t size) { - static_assert(std::is_pod::value, "smalloc() called on C++ type"); + static_assert(std::is_pod_v, "smalloc() called on C++ type"); ptr = static_cast(save_malloc(name, file, line, size)); } /** C++ helper for snew_aligned(). */ @@ -226,22 +226,21 @@ template static inline void gmx_snew_aligned_impl(const char* name, const char* file, int line, T*& ptr, size_t nelem, size_t alignment) { - static_assert(std::is_pod::value, "snew_aligned() called on C++ type"); + static_assert(std::is_pod_v, "snew_aligned() called on C++ type"); ptr = static_cast(save_calloc_aligned(name, file, line, nelem, sizeof(T), alignment)); } /** C++ helper for sfree(). */ template static inline void gmx_sfree_impl(const char* name, const char* file, int line, T* ptr) { - static_assert(std::is_pod::value || std::is_void::value, "sfree() called on C++ type"); + static_assert(std::is_pod_v || std::is_void_v, "sfree() called on C++ type"); save_free(name, file, line, ptr); } /** C++ helper for sfree_aligned(). */ template static inline void gmx_sfree_aligned_impl(const char* name, const char* file, int line, T* ptr) { - static_assert(std::is_pod::value || std::is_void::value, - "sfree_aligned() called on C++ type"); + static_assert(std::is_pod_v || std::is_void_v, "sfree_aligned() called on C++ type"); save_free_aligned(name, file, line, ptr); } /*! \} */ diff --git a/src/gromacs/utility/tests/arrayref.cpp b/src/gromacs/utility/tests/arrayref.cpp index 8c9e2759ec..17cd919ce6 100644 --- a/src/gromacs/utility/tests/arrayref.cpp +++ b/src/gromacs/utility/tests/arrayref.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020, 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. @@ -176,7 +176,7 @@ using makeConstIf_t = std::conditional_t; TYPED_TEST(ArrayRefTest, ConstructFromVectorWorks) { - makeConstIf_t::value, std::vector> v( + makeConstIf_t, std::vector> v( this->a, this->a + aSize); typename TestFixture::ArrayRefType arrayRef(v); this->runTests(v.data(), arrayRef); diff --git a/src/gromacs/utility/tests/inmemoryserializer.cpp b/src/gromacs/utility/tests/inmemoryserializer.cpp index 1a45090003..2db9b643f5 100644 --- a/src/gromacs/utility/tests/inmemoryserializer.cpp +++ b/src/gromacs/utility/tests/inmemoryserializer.cpp @@ -162,7 +162,7 @@ protected: c_int64Value, c_intAndFloat64.doubleValue_, integerSizeDependentTestingValue(), - std::is_same::value + std::is_same_v ? static_cast(c_intAndFloat64.doubleValue_) : static_cast(c_intAndFloat32.floatValue_) }; @@ -176,8 +176,8 @@ protected: c_int64ValueSwapped, c_intAndFloat64Swapped.doubleValue_, integerSizeDependentTestingValueEndianessSwapped(), - std::is_same::value ? static_cast(c_intAndFloat32Swapped.floatValue_) - : static_cast(c_intAndFloat64Swapped.doubleValue_) + std::is_same_v ? static_cast(c_intAndFloat32Swapped.floatValue_) + : static_cast(c_intAndFloat64Swapped.doubleValue_) }; }; @@ -189,7 +189,7 @@ TEST_F(InMemorySerializerTest, Roundtrip) auto buffer = serializer.finishAndGetBuffer(); - InMemoryDeserializer deserializer(buffer, std::is_same::value); + InMemoryDeserializer deserializer(buffer, std::is_same_v); SerializerValues deserialisedValues = deserialize(&deserializer); @@ -204,7 +204,7 @@ TEST_F(InMemorySerializerTest, RoundtripWithEndianessSwap) auto buffer = serializerWithSwap.finishAndGetBuffer(); - InMemoryDeserializer deserializerWithSwap(buffer, std::is_same::value, + InMemoryDeserializer deserializerWithSwap(buffer, std::is_same_v, EndianSwapBehavior::Swap); SerializerValues deserialisedValues = deserialize(&deserializerWithSwap); @@ -220,7 +220,7 @@ TEST_F(InMemorySerializerTest, SerializerExplicitEndianessSwap) auto buffer = serializerWithSwap.finishAndGetBuffer(); - InMemoryDeserializer deserializerWithOutSwap(buffer, std::is_same::value); + InMemoryDeserializer deserializerWithOutSwap(buffer, std::is_same_v); SerializerValues deserialisedValues = deserialize(&deserializerWithOutSwap); checkSerializerValuesforEquality(endianessSwappedValues_, deserialisedValues); @@ -234,7 +234,7 @@ TEST_F(InMemorySerializerTest, DeserializerExplicitEndianessSwap) auto buffer = serializer.finishAndGetBuffer(); - InMemoryDeserializer deserializerWithSwap(buffer, std::is_same::value, + InMemoryDeserializer deserializerWithSwap(buffer, std::is_same_v, EndianSwapBehavior::Swap); SerializerValues deserialisedValues = deserialize(&deserializerWithSwap); -- 2.22.0