Add ssize and remove static_casts
authorRoland Schulz <roland.schulz@intel.com>
Tue, 5 Feb 2019 23:51:26 +0000 (15:51 -0800)
committerChristian Blau <cblau@gwdg.de>
Thu, 7 Feb 2019 10:26:58 +0000 (11:26 +0100)
Fixes #2826

Change-Id: I8cb3b64764798b164b355e71fb10874b49060a0a

42 files changed:
src/gromacs/analysisdata/arraydata.cpp
src/gromacs/analysisdata/dataframe.cpp
src/gromacs/analysisdata/dataframe.h
src/gromacs/analysisdata/datastorage.cpp
src/gromacs/analysisdata/framelocaldata.h
src/gromacs/analysisdata/modules/frameaverager.h
src/gromacs/analysisdata/modules/lifetime.cpp
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/domdec/partition.cpp
src/gromacs/essentialdynamics/edsam.cpp
src/gromacs/ewald/pme_load_balancing.cpp
src/gromacs/gmxana/gmx_trjcat.cpp
src/gromacs/gmxana/thermochemistry.cpp
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/hardware/hardwaretopology.cpp
src/gromacs/mdlib/nbnxn_atomdata.cpp
src/gromacs/mdlib/nbnxn_grid.cpp
src/gromacs/mdlib/nbnxn_search.cpp
src/gromacs/mdrun/legacymdrunoptions.cpp
src/gromacs/mdrun/minimize.cpp
src/gromacs/onlinehelp/helpformat.cpp
src/gromacs/options/basicoptions.cpp
src/gromacs/options/basicoptions.h
src/gromacs/pulling/pull.cpp
src/gromacs/pulling/pullutil.cpp
src/gromacs/selection/nbsearch.cpp
src/gromacs/selection/nbsearch.h
src/gromacs/selection/params.cpp
src/gromacs/selection/parsetree.cpp
src/gromacs/selection/poscalc.cpp
src/gromacs/selection/scanner_internal.cpp
src/gromacs/taskassignment/resourcedivision.cpp
src/gromacs/topology/forcefieldparameters.cpp
src/gromacs/topology/index.cpp
src/gromacs/topology/mtop_lookup.h
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/residuetypes.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/modules/surfacearea.cpp
src/gromacs/utility/basedefinitions.h
src/testutils/cmdlinetest.cpp

index bea6e7ad33042fcd6e305f9547ffd9436a57cfe7..8be6b94614bccdd4533b4efe83a5388b0392fc82 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,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.
@@ -104,7 +104,7 @@ AbstractAnalysisArrayData::setRowCount(int rowCount)
     GMX_RELEASE_ASSERT(!isAllocated(),
                        "Cannot change row count after data has been allocated");
     GMX_RELEASE_ASSERT(bUniformX_ || xvalue_.empty()
-                       || rowCount == static_cast<int>(xvalue_.size()),
+                       || rowCount == ssize(xvalue_),
                        "X axis set with setXAxisValue() does not match the row count");
     xvalue_.resize(rowCount);
     if (bUniformX_ && rowCount > rowCount_)
@@ -155,7 +155,7 @@ AbstractAnalysisArrayData::setXAxisValue(int row, real value)
     {
         GMX_RELEASE_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
     }
-    else if (row >= static_cast<int>(xvalue_.size()))
+    else if (row >= ssize(xvalue_))
     {
         xvalue_.resize(row + 1);
     }
index fcc104e4679451b962fdeacc52b0478c560a8660..9375b2cb5059d742fe92a837612cedcbe4296d6f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2017,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.
@@ -188,7 +188,7 @@ AnalysisDataFrameRef::AnalysisDataFrameRef(
     GMX_ASSERT(columnCount >= 0, "Invalid column count");
     GMX_ASSERT(pointSets_.size() == 1U,
                "Subsets of frames only supported with simple data");
-    GMX_ASSERT(firstColumn + columnCount <= static_cast<int>(values_.size()),
+    GMX_ASSERT(firstColumn + columnCount <= ssize(values_),
                "Invalid last column");
 }
 
index 2646d0112711da97aa69c9af7ddd0e6aa298232c..883722985f2e2b619c94772b4b403b211b218f84 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2017,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.
@@ -655,7 +655,7 @@ class AnalysisDataFrameRef
             GMX_ASSERT(isValid(), "Invalid data frame accessed");
             GMX_ASSERT(pointSets_.size() == 1U && pointSets_[0].firstColumn() == 0,
                        "Convenience method not available for multiple point sets");
-            GMX_ASSERT(i >= 0 && i < static_cast<int>(values_.size()),
+            GMX_ASSERT(i >= 0 && i < ssize(values_),
                        "Out of range data access");
             return values_[i];
         }
index c80e91922377da7b8aadb6168223681bbbfe9687..1379f93f843ad1a49f3f634c9c99bfec90edefed 100644 (file)
@@ -633,7 +633,7 @@ AnalysisDataStorageFrameData::finishFrame(bool bMultipoint)
     status_ = eFinished;
     if (!bMultipoint)
     {
-        GMX_RELEASE_ASSERT(static_cast<int>(pointSets_.size()) == baseData().dataSetCount(),
+        GMX_RELEASE_ASSERT(ssize(pointSets_) == baseData().dataSetCount(),
                            "Point sets created for non-multipoint data");
         values_ = builder_->values_;
         builder_->clearValues();
index 41f00390310e4a58727d327a739d7f397170bdd5..5d086b34a133cc2daf90c33a9b05907f34b069e8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2017,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.
@@ -83,7 +83,7 @@ class AnalysisDataFrameLocalDataSetHandle
         //! Accesses a single value in the data set.
         ValueType &value(int column)
         {
-            GMX_ASSERT(column >= 0 && column < static_cast<int>(values_.size()),
+            GMX_ASSERT(column >= 0 && column < ssize(values_),
                        "Invalid column index");
             return values_[column];
         }
@@ -239,7 +239,7 @@ class AnalysisDataFrameLocalData
         {
             GMX_RELEASE_ASSERT(!isInitialized(),
                                "Cannot change value count after init()");
-            GMX_RELEASE_ASSERT(dataSet >= 0 && dataSet < static_cast<int>(dataSetColumns_.size()) - 1,
+            GMX_RELEASE_ASSERT(dataSet >= 0 && dataSet < ssize(dataSetColumns_) - 1,
                                "Invalid data set index");
             GMX_RELEASE_ASSERT(columnCount >= 0,
                                "Invalid column count");
index 58604f04fe4cb8258991dbbffcb14bd36d290bf5..96562ee3843684697758581fb05cd091a0596bc9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,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.
@@ -155,7 +155,7 @@ class AnalysisDataFrameAverager
          */
         int sampleCount(int index) const
         {
-            GMX_ASSERT(index >= 0 && index <= static_cast<int>(values_.size()),
+            GMX_ASSERT(index >= 0 && index <= ssize(values_),
                        "Invalid column index");
             GMX_ASSERT(bFinished_,
                        "Values available only after finished() has been called");
index 5c120a24506be6526a0d63820a51e3d12631767f..6249e8c2beafd81297346eb1ee0f71b3566af176 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,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.
@@ -166,7 +166,7 @@ AnalysisDataLifetimeModule::pointsAdded(const AnalysisDataPointSetRef &points)
     // This assumption is strictly not necessary, but this is how the
     // framework works currently, and makes the code below simpler.
     GMX_ASSERT(points.firstColumn() == 0
-               && points.lastColumn() == static_cast<int>(impl_->currentLifetimes_[dataSet].size()) - 1,
+               && points.lastColumn() == ssize(impl_->currentLifetimes_[dataSet]) - 1,
                "Point set should cover all columns");
     for (int i = 0; i < points.columnCount(); ++i)
     {
index 566102baff306bfb926099fcd8284297820cfc2a..1e9b1c4ef8cec662e6d3fdd307d2bbcd85d0098f 100644 (file)
@@ -936,7 +936,7 @@ static void add_posres(int mol, int a_mol, int numAtomsInMolecule,
 
     /* Get the position restraint coordinates from the molblock */
     a_molb = mol*numAtomsInMolecule + a_mol;
-    GMX_ASSERT(a_molb < static_cast<int>(molb->posres_xA.size()), "We need a sufficient number of position restraint coordinates");
+    GMX_ASSERT(a_molb < ssize(molb->posres_xA), "We need a sufficient number of position restraint coordinates");
     ip->posres.pos0A[XX] = molb->posres_xA[a_molb][XX];
     ip->posres.pos0A[YY] = molb->posres_xA[a_molb][YY];
     ip->posres.pos0A[ZZ] = molb->posres_xA[a_molb][ZZ];
@@ -980,7 +980,7 @@ static void add_fbposres(int mol, int a_mol, int numAtomsInMolecule,
 
     /* Get the position restraint coordinats from the molblock */
     a_molb = mol*numAtomsInMolecule + a_mol;
-    GMX_ASSERT(a_molb < static_cast<int>(molb->posres_xA.size()), "We need a sufficient number of position restraint coordinates");
+    GMX_ASSERT(a_molb < ssize(molb->posres_xA), "We need a sufficient number of position restraint coordinates");
     /* Take reference positions from A position of normal posres */
     ip->fbposres.pos0[XX] = molb->posres_xA[a_molb][XX];
     ip->fbposres.pos0[YY] = molb->posres_xA[a_molb][YY];
index bd00656df2b7468617981be14cf04a62f4913f31..3a1ea5a7dce8a452068d9f47cd02b4038e60be47 100644 (file)
@@ -2112,7 +2112,7 @@ static void setup_dd_communication(gmx_domdec_t *dd,
                     cg0 = cg1 - cd->ind[p-1].nrecv[zone];
                 }
 
-                const int numThreads = static_cast<int>(comm->dth.size());
+                const int numThreads = gmx::ssize(comm->dth);
 #pragma omp parallel for num_threads(numThreads) schedule(static)
                 for (int th = 0; th < numThreads; th++)
                 {
index 8ad287bf6d36de46478344b519e675904dfa5296..8ba72b64dca4462e1270c0a1eb50e8e56306fcc0 100644 (file)
@@ -2362,7 +2362,7 @@ static void crosscheck_edi_file_vs_checkpoint(const gmx_edsam &ed, edsamhistory_
         }
     }
 
-    if (static_cast<int>(ed.edpar.size()) != EDstate->nED)
+    if (gmx::ssize(ed.edpar) != EDstate->nED)
     {
         gmx_fatal(FARGS, "The number of essential dynamics / flooding groups is not consistent.\n"
                   "There are %d ED groups in the .cpt file, but %zu in the .edi file!\n"
index 8ff5939072338d9b96b05c6ca7f491a289e3932d..9c147967a97eea1f985c385c195fe9680dc86a8b 100644 (file)
@@ -489,7 +489,7 @@ static void switch_to_stage1(pme_load_balancing_t *pme_lb)
      * maxRelativeSlowdownAccepted times the fastest setup.
      */
     pme_lb->start = pme_lb->lower_limit;
-    while (pme_lb->start + 1 < static_cast<int>(pme_lb->setup.size()) &&
+    while (pme_lb->start + 1 < gmx::ssize(pme_lb->setup) &&
            (pme_lb->setup[pme_lb->start].count == 0 ||
             pme_lb->setup[pme_lb->start].cycles >
             pme_lb->setup[pme_lb->fastest].cycles*maxRelativeSlowdownAccepted))
@@ -647,7 +647,7 @@ pme_load_balance(pme_load_balancing_t      *pme_lb,
 
         do
         {
-            if (pme_lb->cur+1 < static_cast<int>(pme_lb->setup.size()))
+            if (pme_lb->cur+1 < gmx::ssize(pme_lb->setup))
             {
                 /* We had already generated the next setup */
                 OK = TRUE;
index 6f7f252fc6fc194f8a64192549e4d25ca3bfab51..5ba16ed1d8e25ac65494a7204934fef07c5e2a6e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * 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.
@@ -553,7 +553,7 @@ int gmx_trjcat(int argc, char *argv[])
         gmx_fatal(FARGS, "No input files!" );
     }
 
-    if (bDeMux && static_cast<int>(inFiles.size()) != nset)
+    if (bDeMux && ssize(inFiles) != nset)
     {
         gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.size(), nset);
     }
@@ -582,14 +582,14 @@ int gmx_trjcat(int argc, char *argv[])
     {
         gmx_fatal(FARGS, "Don't know what to do with more than 1 output file if  not demultiplexing");
     }
-    else if (bDeMux && static_cast<int>(outFiles.size()) != nset && outFiles.size() != 1)
+    else if (bDeMux && ssize(outFiles) != nset && outFiles.size() != 1)
     {
         gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.size());
     }
     if (bDeMux)
     {
         auto outFilesDemux = gmx::copyOf(outFiles);
-        if (static_cast<int>(outFilesDemux.size()) != nset)
+        if (gmx::ssize(outFilesDemux) != nset)
         {
             std::string name = outFilesDemux[0];
             outFilesDemux.resize(nset);
index 52c5a0f209a5295fca97db9789e97e29ca38bc49..f8aa9d5a58f16ab6983a73d05cf896abd70aaeb7 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.
@@ -214,8 +214,8 @@ double calcSchlitterEntropy(gmx::ArrayRef<const real> eigval,
     double evcorr = NANO*NANO*AMU;
     if (debug)
     {
-        fprintf(debug, "n = %d, kteh = %g evcorr = %g\n",
-                static_cast<int>(eigval.size()), kteh, evcorr);
+        fprintf(debug, "n = %td, kteh = %g evcorr = %g\n",
+                ssize(eigval), kteh, evcorr);
     }
     double deter = 0;
     for (gmx::index i = nskip; i < eigval.size(); i++)
index 734638db8691b2a155e2d42183c92d0515874e93..b01d4cea0aeb68623f958a3f5693062cf2109e81 100644 (file)
@@ -140,7 +140,7 @@ choose_ff_impl(const char *ffsel,
                char *ffdir, int ffdir_maxlen)
 {
     std::vector<gmx::DataFileInfo> ffdirs = fflib_enumerate_forcefields();
-    const int nff = static_cast<int>(ffdirs.size());
+    const int nff = ssize(ffdirs);
 
     /* Replace with unix path separators */
 #if DIR_SEPARATOR != '/'
index ae2ce7670640fd04810bf1d7d64f8975b94e1205..c8a15545c8c1753901604947cde2ae397ecc4f6c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
@@ -325,7 +325,7 @@ parseHwLocCache(hwloc_topology_t                   topo,
                                                static_cast<std::size_t>(cache->attr->cache.size),
                                                static_cast<int>(cache->attr->cache.linesize),
                                                static_cast<int>(cache->attr->cache.associativity),
-                                               std::max(static_cast<int>(hwThreads.size()), 1)
+                                               std::max<int>(hwThreads.size(), 1)
                                            } );
             }
         }
index 6e97d4e3a6c83595f75c0e4f17df5a7252324648..d5076d967ee7b3a9523e9826a1c3f00db58d6af6 100644 (file)
@@ -1436,7 +1436,7 @@ static void nbnxn_atomdata_add_nbat_f_to_f_stdreduce(nbnxn_atomdata_t *nbat,
                 int i1 = (b+1)*NBNXN_BUFFERFLAG_SIZE*nbat->fstride;
 
                 nfptr = 0;
-                for (int out = 1; out < static_cast<gmx::index>(nbat->out.size()); out++)
+                for (int out = 1; out < gmx::ssize(nbat->out); out++)
                 {
                     if (bitmask_is_set(flags->flag[b], out))
                     {
index 93a93fbb64c092c11821a37dffda22417d4e7b75..a0b587523c68f039b6076913afb86a9eed93963e 100644 (file)
@@ -1505,7 +1505,7 @@ void nbnxn_put_on_grid(nbnxn_search_t                  nbs,
     {
         nbat->natoms_local = nbat->numAtoms();
     }
-    if (ddZone == static_cast<int>(nbs->grid.size()) - 1)
+    if (ddZone == gmx::ssize(nbs->grid) - 1)
     {
         /* We are done setting up all grids, we can resize the force buffers */
         nbat->resizeForceBuffers();
index a06c309bdd628b8d3c357e7ac80b7cd89583dd23..10359ab5ab8f2fcff5b23e72b326b964a4adc8d0 100644 (file)
@@ -3261,7 +3261,7 @@ static void setBufferFlags(const NbnxnPairlistCpu &nbl,
                            gmx_bitmask_t          *gridj_flag,
                            const int               th)
 {
-    if (static_cast<gmx::index>(nbl.cj.size()) > ncj_old_j)
+    if (gmx::ssize(nbl.cj) > ncj_old_j)
     {
         int cbFirst = nbl.cj[ncj_old_j].cj >> gridj_flag_shift;
         int cbLast  = nbl.cj.back().cj >> gridj_flag_shift;
@@ -3945,7 +3945,7 @@ static void rebalanceSimpleLists(int                                  numLists,
 
             if (cjGlobal + src->ncjInUse > cjStart)
             {
-                for (gmx::index i = 0; i < static_cast<gmx::index>(src->ci.size()) && cjGlobal < cjEnd; i++)
+                for (gmx::index i = 0; i < gmx::ssize(src->ci) && cjGlobal < cjEnd; i++)
                 {
                     const nbnxn_ci_t *srcCi = &src->ci[i];
                     int               ncj   = srcCi->cj_ind_end - srcCi->cj_ind_start;
index 188d4b3f365dcb5c933376cd207d38e50f3acfc8..9d02e982d433465c71172c05aa4dcff83a849339 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,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.
@@ -91,8 +91,8 @@ int LegacyMdrunOptions::updateFromCommandLine(int argc, char **argv, ArrayRef<co
     }
 
     if (!parse_common_args(&argc, argv, PCA_Flags,
-                           static_cast<int>(filenames.size()), filenames.data(), asize(pa), pa,
-                           static_cast<int>(desc.size()), desc.data(), 0, nullptr, &oenv))
+                           ssize(filenames), filenames.data(), asize(pa), pa,
+                           ssize(desc), desc.data(), 0, nullptr, &oenv))
     {
         return 0;
     }
@@ -140,7 +140,7 @@ int LegacyMdrunOptions::updateFromCommandLine(int argc, char **argv, ArrayRef<co
 
     // now check for a multi-simulation
     ArrayRef<const std::string> multidir = opt2fnsIfOptionSet("-multidir",
-                                                              static_cast<int>(filenames.size()),
+                                                              ssize(filenames),
                                                               filenames.data());
 
     if (replExParams.exchangeInterval != 0 && multidir.size() < 2)
@@ -170,7 +170,7 @@ int LegacyMdrunOptions::updateFromCommandLine(int argc, char **argv, ArrayRef<co
 #endif
 
     if (!opt2bSet("-cpi",
-                  static_cast<int>(filenames.size()), filenames.data()))
+                  ssize(filenames), filenames.data()))
     {
         // If we are not starting from a checkpoint we never allow files to be appended
         // to, since that has caused a ton of strange behaviour and bugs in the past.
@@ -191,13 +191,13 @@ int LegacyMdrunOptions::updateFromCommandLine(int argc, char **argv, ArrayRef<co
     continuationOptions.appendFilesOptionSet = opt2parg_bSet("-append", asize(pa), pa);
 
     handleRestart(cr, ms, bTryToAppendFiles,
-                  static_cast<int>(filenames.size()),
+                  ssize(filenames),
                   filenames.data(),
                   &continuationOptions.appendFiles,
                   &continuationOptions.startedFromCheckpoint);
 
     mdrunOptions.rerun            = opt2bSet("-rerun",
-                                             static_cast<int>(filenames.size()),
+                                             ssize(filenames),
                                              filenames.data());
     mdrunOptions.ntompOptionIsSet = opt2parg_bSet("-ntomp", asize(pa), pa);
 
index 915fd4063eeec7c534f7c36e3112685bdab1657c..371419c54be89dd7e2f2aecb61e13b46339dc54e 100644 (file)
@@ -665,7 +665,7 @@ static bool do_em_step(const t_commrec *cr,
 
             /* OpenMP does not supported unsigned loop variables */
 #pragma omp for schedule(static) nowait
-            for (int i = 0; i < static_cast<int>(s2->cg_gl.size()); i++)
+            for (int i = 0; i < gmx::ssize(s2->cg_gl); i++)
             {
                 s2->cg_gl[i] = s1->cg_gl[i];
             }
@@ -2952,9 +2952,9 @@ Integrator::do_nm()
         /* write progress */
         if (bIsMaster && mdrunOptions.verbose)
         {
-            fprintf(stderr, "\rFinished step %d out of %d",
-                    static_cast<int>(std::min(atom+nnodes, atom_index.size())),
-                    static_cast<int>(atom_index.size()));
+            fprintf(stderr, "\rFinished step %d out of %td",
+                    std::min<int>(atom+nnodes, atom_index.size()),
+                    ssize(atom_index));
             fflush(stderr);
         }
     }
index 777ad247dd83b6160a3370f4d1425f3756192d87..4d9ce48aebc321685a328b869def2d69c7f3e169 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2016,2017,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.
@@ -110,7 +110,7 @@ class TextTableFormatter::Impl
             //! Whether there are lines remaining for textForNextLine().
             bool hasLinesRemaining() const
             {
-                return nextLineIndex_ < static_cast<int>(lines_.size());
+                return nextLineIndex_ < ssize(lines_);
             }
             /*! \brief
              * Returns the text for the next line.
@@ -182,7 +182,7 @@ class TextTableFormatter::Impl
          */
         ColumnData &columnData(int index)
         {
-            GMX_ASSERT(index >= 0 && index < static_cast<int>(columns_.size()),
+            GMX_ASSERT(index >= 0 && index < ssize(columns_),
                        "Invalid column index");
             return columns_[index];
         }
index 57bd2106f9c0206ee2e5dc6e273a50e5fd2cd980..26d3d049e6855c95cd7496a7e04c0767e24ba302 100644 (file)
@@ -603,7 +603,7 @@ std::string EnumOptionStorage::formatExtraDescription() const
 
 std::string EnumOptionStorage::formatSingleValue(const int &value) const
 {
-    if (value < 0 || value >= static_cast<int>(allowed_.size()))
+    if (value < 0 || value >= ssize(allowed_))
     {
         return std::string();
     }
index abfe841cdea42e9ad4600f29c429f543e9e97732..9e35ca08a9019ec2fae6121db8a68b4e26554002 100644 (file)
@@ -410,7 +410,7 @@ class EnumIndexStore : public IOptionValueStore<int>
             }
         }
 
-        int valueCount() override { return static_cast<int>(intStore_.size()); }
+        int valueCount() override { return ssize(intStore_); }
         ArrayRef<int> values() override { return intStore_; }
         void clear() override
         {
index f0f05a0cf478521f85ca5a0705077264dabb3340..2d09c42336ebaf2c0bb37a40eb05baa60db4d6dd 100644 (file)
@@ -1376,7 +1376,7 @@ void register_external_pull_potential(struct pull_t *pull,
     GMX_RELEASE_ASSERT(pull != nullptr, "register_external_pull_potential called before init_pull");
     GMX_RELEASE_ASSERT(provider != nullptr, "register_external_pull_potential called with NULL as provider name");
 
-    if (coord_index < 0 || coord_index >= static_cast<int>(pull->coord.size()))
+    if (coord_index < 0 || coord_index >= gmx::ssize(pull->coord))
     {
         gmx_fatal(FARGS, "Module '%s' attempted to register an external potential for pull coordinate %d which is out of the pull coordinate range %d - %zu\n",
                   provider, coord_index + 1, 1, pull->coord.size());
@@ -1453,7 +1453,7 @@ void apply_external_pull_coord_force(struct pull_t        *pull,
 {
     pull_coord_work_t *pcrd;
 
-    GMX_ASSERT(coord_index >= 0 && coord_index < static_cast<int>(pull->coord.size()), "apply_external_pull_coord_force called with coord_index out of range");
+    GMX_ASSERT(coord_index >= 0 && coord_index < gmx::ssize(pull->coord), "apply_external_pull_coord_force called with coord_index out of range");
 
     if (pull->comm.bParticipate)
     {
index 6d686f4689a08906a7d579e634f1c683291ace14..c33a110340c1505a93860f0568b05be186b30d59 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * 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.
@@ -957,7 +957,7 @@ bool pullCheckPbcWithinGroup(const pull_t                  &pull,
     {
         return true;
     }
-    GMX_ASSERT(groupNr < static_cast<int>(pull.group.size()), "groupNr is out of range");
+    GMX_ASSERT(groupNr < gmx::ssize(pull.group), "groupNr is out of range");
 
     /* Check PBC if the group uses a PBC reference atom treatment. */
     const pull_group_work_t &group = pull.group[groupNr];
index 275b91788d74deb9ecc149db4b079d891dcccded..3715ca89b7524b54dfd322a389dd95ad0a650cdb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,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.
@@ -1099,7 +1099,7 @@ bool AnalysisNeighborhoodPairSearchImpl::searchNext(Action action)
                 {
                     continue;
                 }
-                const int cellSize = static_cast<int>(search_.cells_[ci].size());
+                const int cellSize = ssize(search_.cells_[ci]);
                 for (; cai < cellSize; ++cai)
                 {
                     const int i = search_.cells_[ci][cai];
index 47d681d076ed4e2097573d2524c00b8539a0d38d..16fb23f4799fc4401c80d4c6a3f2ca40f68633b4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,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.
@@ -138,7 +138,7 @@ class AnalysisNeighborhoodPositions
         AnalysisNeighborhoodPositions &
         exclusionIds(ArrayRef<const int> ids)
         {
-            GMX_ASSERT(static_cast<int>(ids.size()) == count_,
+            GMX_ASSERT(ssize(ids) == count_,
                        "Exclusion id array should match the number of positions");
             exclusionIds_ = ids.data();
             return *this;
index a2a313eab1251d255b052c4b4a525de8596451a1..28512605ef84b003d77df7526fcc8c3ff523da8f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,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.
@@ -438,7 +438,7 @@ parse_values_varnum(const SelectionParserValueList    &values,
 
     param->flags &= ~SPAR_DYNAMIC;
     /* Compute number of values, considering also integer ranges. */
-    int valueCount = static_cast<int>(values.size());
+    int valueCount = ssize(values);
     if (param->val.type == INT_VALUE)
     {
         SelectionParserValueList::const_iterator value;
index 1b504071cc08d14999842e8b423e614d7d0fa5ab..dcbaa4ac1e4b1ecbe328a7e06d723621b9eded5e 100644 (file)
@@ -1214,5 +1214,5 @@ bool
 _gmx_sel_parser_should_finish(yyscan_t scanner)
 {
     gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
-    return static_cast<int>(sc->sel.size()) == _gmx_sel_lexer_exp_selcount(scanner);
+    return gmx::ssize(sc->sel) == _gmx_sel_lexer_exp_selcount(scanner);
 }
index ac877206d3b89ef542061012d31143505dff12a1..ffcb0cd3880278aec72c072ce663ba7c6cc7568f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,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.
@@ -137,7 +137,7 @@ class PositionCalculationCollection::Impl
             for (int i = 0; i < size; ++i)
             {
                 const int ii = index[i];
-                GMX_ASSERT(ii >= 0 && ii <= static_cast<int>(mapToFrameAtoms_.size())
+                GMX_ASSERT(ii >= 0 && ii <= ssize(mapToFrameAtoms_)
                            && mapToFrameAtoms_[ii] != -1,
                            "Invalid input atom index");
                 tmpFrameAtoms_[i] = mapToFrameAtoms_[ii];
index abb96a5d6c6d6840b32eefd18d967fc8a7be011c..bfe390150568d59a341b8694a4ece225141ed7c5 100644 (file)
@@ -383,7 +383,7 @@ _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
     state->sc        = sc;
     state->bGroups   = bGroups;
     state->grps      = grps;
-    state->nexpsel   = (maxnr > 0 ? static_cast<int>(sc->sel.size()) + maxnr : -1);
+    state->nexpsel   = (maxnr > 0 ? gmx::ssize(sc->sel) + maxnr : -1);
 
     state->statusWriter = statusWriter;
 
index 5fa35b34eb1ede13742df5a94d322535ed7153b6..da85789f5f0ff21fb1dceb6299907481c77a525e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -420,7 +420,7 @@ int get_nthreads_mpi(const gmx_hw_info_t    *hwinfo,
 
     /* nonbondedOnGpu might be false e.g. because this simulation uses
      * the group scheme, or is a rerun with energy groups. */
-    ngpu = (nonbondedOnGpu ? static_cast<int>(gpuIdsToUse.size()) : 0);
+    ngpu = (nonbondedOnGpu ? gmx::ssize(gpuIdsToUse) : 0);
 
     if (inputrec->cutoff_scheme == ecutsGROUP)
     {
index 18dfcd21d0d17e417d9755429ab8a79e49478585..ff34714a55de52a9b383435ec61398c3a35ecfb5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,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.
@@ -54,7 +54,7 @@ static void pr_cmap(FILE *fp, int indent, const char *title,
     {
         fprintf(fp, "%s\n", title);
 
-        for (i = 0; i < static_cast<int>(cmap_grid->cmapdata.size()); i++)
+        for (i = 0; i < gmx::ssize(cmap_grid->cmapdata); i++)
         {
             idx = -180.0;
             fprintf(fp, "%8s %8s %8s %8s\n", "V", "dVdx", "dVdy", "d2dV");
index 6e2bca567d76abbca96f6bee45069e7b2f99518d..86088de42b9db32f313e34f4972d6dabdd29a25b 100644 (file)
@@ -629,7 +629,7 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
 
             /* Create a Non-Protein group */
             aid = mk_aid(atoms, restype, "Protein", FALSE);
-            if ((!aid.empty()) && (static_cast<int>(aid.size()) < atoms->nr))
+            if ((!aid.empty()) && (gmx::ssize(aid) < atoms->nr))
             {
                 add_grp(gb, gn, aid, "non-Protein");
             }
@@ -643,7 +643,7 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
 
             /* Solvent, create a negated group too */
             aid = mk_aid(atoms, restype, "Water", FALSE);
-            if ((!aid.empty()) && (static_cast<int>(aid.size()) < atoms->nr))
+            if ((!aid.empty()) && (gmx::ssize(aid) < atoms->nr))
             {
                 add_grp(gb, gn, aid, "non-Water");
             }
index 558ceb6163c0273acab5f9dd1c5205311094213a..9926cd5171168489e7a12c313ce5f5b73f563bdc 100644 (file)
@@ -78,7 +78,7 @@ mtopGetMolblockIndex(const gmx_mtop_t *mtop,
 {
     GMX_ASSERT(globalAtomIndex >= 0 && globalAtomIndex < mtop->natoms, "The atom index to look up should be within range");
     GMX_ASSERT(moleculeBlock != nullptr, "molBlock can not be NULL");
-    GMX_ASSERT(*moleculeBlock >= 0 && *moleculeBlock < static_cast<int>(mtop->moleculeBlockIndices.size()), "The starting molecule block index for the search should be within range and moleculeBlockIndices should not be empty");
+    GMX_ASSERT(*moleculeBlock >= 0 && *moleculeBlock < gmx::ssize(mtop->moleculeBlockIndices), "The starting molecule block index for the search should be within range and moleculeBlockIndices should not be empty");
 
     /* Search the molecule block index using bisection */
     int molBlock0 = -1;
index 8ca8b32e57a42a045d4e13e507858879d0508816..ad4c3a3403c9b571e3a011c12479dc0adf89a1d4 100644 (file)
@@ -412,9 +412,9 @@ gmx_mtop_ilistloop_next(gmx_mtop_ilistloop_t    iloop,
     }
 
     iloop->mblock++;
-    if (iloop->mblock >= static_cast<int>(iloop->mtop->molblock.size()))
+    if (iloop->mblock >= gmx::ssize(iloop->mtop->molblock))
     {
-        if (iloop->mblock == static_cast<int>(iloop->mtop->molblock.size()) &&
+        if (iloop->mblock == gmx::ssize(iloop->mtop->molblock) &&
             iloop->mtop->bIntermolecularInteractions)
         {
             *nmol      = 1;
index 21cc485fe4689e8dab81180635429ac5dde77d75..453d7254db0992d7a45157477cd4fba4a98f50f2 100644 (file)
@@ -162,7 +162,7 @@ int ResidueType::indexFromResidueName(const std::string &residueName) const
 
 const std::string ResidueType::nameFromResidueIndex(int index) const
 {
-    if (index >= 0 && index < static_cast<int>(impl_->entry.size()))
+    if (index >= 0 && index < gmx::ssize(impl_->entry))
     {
         return impl_->entry[index].residueName;
     }
index d476fa5c134224993136f134190d42054658b954..ff81c402e453f8b76f1c5efb5ff7d90d134e95b8 100644 (file)
@@ -200,7 +200,7 @@ class AnglePositionIterator
         //! Returns the currently active selection.
         const Selection &currentSelection() const
         {
-            GMX_ASSERT(currentSelection_ < static_cast<int>(selections_.size()),
+            GMX_ASSERT(currentSelection_ < ssize(selections_),
                        "Accessing an invalid selection");
             return selections_[currentSelection_];
         }
index de253b201a0fada8f2e213a4db5267974cf95abf..98dc92a40c85986908484620bf5998d5edea9453 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,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.
@@ -206,7 +206,7 @@ IndexFileWriterModule::pointsAdded(const AnalysisDataPointSetRef &points)
     if (points.firstColumn() == 0)
     {
         ++currentGroup_;
-        GMX_RELEASE_ASSERT(currentGroup_ < static_cast<int>(groups_.size()),
+        GMX_RELEASE_ASSERT(currentGroup_ < ssize(groups_),
                            "Too few groups initialized");
         if (bFirstFrame || groups_[currentGroup_].bDynamic)
         {
index 7a6155af68fbadfbc1480daf4be4bb723bd6d738..c6fb7776dfcf0d0b40463eacc34bef9f2cc88ebd 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2007, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,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.
@@ -469,7 +469,7 @@ static std::vector<real> make_unsp(int densit, int cubus)
         GMX_RELEASE_ASSERT(false, "Invalid unit sphere mode");
     }
 
-    const int ndot = static_cast<int>(xus.size())/3;
+    const int ndot = ssize(xus)/3;
 
     /* determine distribution of points in elementary cubes */
     if (cubus)
index 3da407f059242992bcef20aaaa8eaf67f056d96e..cb22dff80ebf835ef3a99015cc858500c9024a75 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * 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.
@@ -70,7 +70,11 @@ namespace gmx
  * Same as ptrdiff_t.
  */
 using index = std::ptrdiff_t;
-}
+
+//! Return signed size of container
+template<typename T>
+index ssize(const T &t) { return t.size(); }
+}  // namespace gmx
 
 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
  * Any other compiler can be added here. */
index 6d6a3b5efeadee714ac924ac0e2a1885d3817e82..1db63fc70891d6e4fbd4552c92498c209056c824 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
@@ -92,7 +92,7 @@ CommandLine::Impl::Impl(const ArrayRef<const char *const> &cmdline)
 {
     args_.reserve(cmdline.size());
     argv_.reserve(cmdline.size() + 1);
-    argc_ = static_cast<int>(cmdline.size());
+    argc_ = ssize(cmdline);
     for (const auto &arg : cmdline)
     {
         char *argCopy = strdup(arg);
@@ -168,7 +168,7 @@ void CommandLine::initFromArray(const ArrayRef<const char *const> &cmdline)
 
 void CommandLine::append(const char *arg)
 {
-    GMX_RELEASE_ASSERT(impl_->argc_ == static_cast<int>(impl_->args_.size()),
+    GMX_RELEASE_ASSERT(impl_->argc_ == ssize(impl_->args_),
                        "Command-line has been modified externally");
     size_t newSize = impl_->args_.size() + 1;
     impl_->args_.reserve(newSize);