Fix double overload in LocalAtomSet code when gmx::index is int
authorChristian Blau <cblau@gwdg.de>
Tue, 3 Sep 2019 10:36:09 +0000 (12:36 +0200)
committerChristian Blau <cblau@gwdg.de>
Wed, 4 Sep 2019 13:58:07 +0000 (15:58 +0200)
In cases where the int type matches the gmx::index (aka ptrdiff) type
two overloaded constructors in LocalAtomSetData became the same, as well
as the overloaded add method. This is now avoided by an enable_if
clause.

Change-Id: I139c7feff141928f71c71d6f6db3ee1bffe325b7

src/gromacs/domdec/localatomsetdata.cpp
src/gromacs/domdec/localatomsetdata.h
src/gromacs/domdec/localatomsetmanager.cpp
src/gromacs/domdec/localatomsetmanager.h
src/gromacs/domdec/tests/localatomsetmanager.cpp
src/gromacs/pulling/pull.cpp
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/swap/swapcoords.cpp

index 7a8899ba48eac05ce22e4622a93e3236d657de7b..3d0e7d53b72c0cd96798503e114570222c3bd45f 100644 (file)
@@ -58,13 +58,6 @@ namespace internal
  * LocalAtomSetData
  */
 
-LocalAtomSetData::LocalAtomSetData(ArrayRef<const int> globalIndex) :
-    globalIndex_(globalIndex.begin(), globalIndex.end()), localIndex_(globalIndex.begin(), globalIndex.end())
-{
-    collectiveIndex_.resize(localIndex_.size());
-    std::iota(collectiveIndex_.begin(), collectiveIndex_.end(), 0);
-}
-
 LocalAtomSetData::LocalAtomSetData(ArrayRef<const index> globalIndex) :
     globalIndex_(globalIndex.begin(), globalIndex.end()), localIndex_(globalIndex.begin(), globalIndex.end())
 {
index 986e26f8f5309190cf8fc76862c779f671312543..5665370fbd48c42ee9177a76822533e92e5ec4f0 100644 (file)
@@ -42,6 +42,7 @@
 #ifndef GMX_DOMDEC_LOCALATOMSETDATA_H
 #define GMX_DOMDEC_LOCALATOMSETDATA_H
 
+#include <numeric>
 #include <vector>
 
 #include "gromacs/utility/arrayref.h"
@@ -70,9 +71,18 @@ class LocalAtomSetData
          * \todo remove this constructor once all indices are represented
          *       as gmx::index instead of int.
          *
+         * \note Not created if the internal int type does match gmx::index
+         *
          * \param[in] globalAtomIndex Indices of the atoms to be managed
          */
-        explicit LocalAtomSetData(ArrayRef<const int> globalAtomIndex);
+        template <typename T = void, typename U = std::enable_if_t<!std::is_same<int, index>::value, T> >
+        explicit LocalAtomSetData(ArrayRef<const int> globalAtomIndex) :
+            globalIndex_(globalAtomIndex.begin(), globalAtomIndex.end()),
+            localIndex_(globalAtomIndex.begin(), globalAtomIndex.end())
+        {
+            collectiveIndex_.resize(localIndex_.size());
+            std::iota(collectiveIndex_.begin(), collectiveIndex_.end(), 0);
+        }
 
         /*! \brief Store the data for an atom set with an index group.
          *
index 7182c954ca2674d464f8811db19e9ea8b3dbed8d..28c5d02c69875acbc13b437787ac8c8e720f67c5 100644 (file)
@@ -74,8 +74,7 @@ LocalAtomSetManager::LocalAtomSetManager() : impl_(new Impl())
 
 LocalAtomSetManager::~LocalAtomSetManager(){}
 
-LocalAtomSet
-LocalAtomSetManager::add(ArrayRef<const int> globalAtomIndex)
+template<> LocalAtomSet LocalAtomSetManager::add<void, void>(ArrayRef<const int> globalAtomIndex)
 {
     impl_->atomSetData_.push_back(std::make_unique<internal::LocalAtomSetData>(globalAtomIndex));
     return LocalAtomSet(*impl_->atomSetData_.back());
index 2b6233ede1c47b635959935b3c19927e97465988..8d6aed53098a6502c6dffa9a30124efa1293fb8a 100644 (file)
@@ -69,17 +69,24 @@ class LocalAtomSetManager
     public:
         LocalAtomSetManager();
         ~LocalAtomSetManager();
-
+#ifndef DOXYGEN
         /*! \brief Add a new atom set to be managed and give back a handle.
          *
          * \todo remove this routine once all indices are represented as
          *       gmx::index instead of int.
          *
+         * \note Not created if the internal int type does match index
+         *
+         * \tparam T template parameter to use SFINAE for conditional function
+         *           activation
+         * \tparam U template parameter for conditional function activation
+         *
          * \param[in] globalAtomIndex Indices of the atoms to be managed
          * \returns Handle to LocalAtomSet.
          */
+        template<typename T = void, typename U = std::enable_if_t< !std::is_same<int, index>::value, T> >
         LocalAtomSet add(ArrayRef<const int> globalAtomIndex);
-
+#endif
         /*! \brief Add a new atom set to be managed and give back a handle.
          *
          * \param[in] globalAtomIndex Indices of the atoms to be managed
index 5db6a08aa0b5f880c2e67a07afd49d85dea5fcfb..aaf2129b547e6534fa46014f4a9e1c74d0233e97 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * 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.
@@ -58,6 +58,8 @@
 namespace gmx
 {
 
+extern template LocalAtomSet LocalAtomSetManager::add<void, void>(ArrayRef<const int> globalAtomIndex);
+
 namespace test
 {
 
index 1745d4c5fa88288e98452310dd6108d1430fc39f..c8a9855743fb3f0cb1a7c49473ede7c4a495432c 100644 (file)
 
 #include "pull_internal.h"
 
+namespace gmx
+{
+extern template LocalAtomSet LocalAtomSetManager::add<void, void>(ArrayRef<const int> globalAtomIndex);
+} // namespace gmx
+
 static int groupPbcFromParams(const t_pull_group &params, bool setPbcRefToPrevStepCOM)
 {
     if (params.nat <= 1)
index dcfa19d05647fb283a99049b880da838b0119972..742b22c6a9f923065e51ef6981457090409d9bbc 100644 (file)
@@ -300,6 +300,8 @@ gmx_enfrot::~gmx_enfrot()
 namespace gmx
 {
 
+extern template LocalAtomSet LocalAtomSetManager::add<void, void>(ArrayRef<const int> globalAtomIndex);
+
 class EnforcedRotation::Impl
 {
     public:
index 83c20218dc612deab5032ac793d3c7eba6fc4812..193354b3f03500488babd83a6802c84b1f6a67c2 100644 (file)
@@ -104,6 +104,8 @@ static const char* DomainString[eDomainNr] = { "not_assigned", "Domain_A", "Doma
 namespace gmx
 {
 
+extern template LocalAtomSet LocalAtomSetManager::add<void, void>(ArrayRef<const int> globalAtomIndex);
+
 /*! \internal
  * \brief Implement Computational Electrophysiology swapping.
  */