lastfilestep = 0;
laststep = 0;
- gmx::ArrayRef<const std::string> filesOrig = opt2fns("-f", NFILE, fnm);
- std::vector<std::string> files(filesOrig.begin(), filesOrig.end());
+ auto files = gmx::copyOf(opt2fns("-f", NFILE, fnm));
if (files.empty())
{
}
if (bDeMux)
{
- std::vector<std::string> outFilesDemux(outFiles.begin(), outFiles.end());
+ auto outFilesDemux = gmx::copyOf(outFiles);
if (static_cast<int>(outFilesDemux.size()) != nset)
{
std::string name = outFilesDemux[0];
snew(settime, inFiles.size() + 1);
snew(cont_type, inFiles.size() + 1);
- std::vector<std::string> inFilesEdited(inFiles.begin(), inFiles.end());
+ auto inFilesEdited = gmx::copyOf(inFiles);
edit_files(inFilesEdited, readtime, timest, settime, cont_type, bSetTime, bSort,
oenv);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, 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.
a.swap(b);
}
+/*! \brief Return a vector that is a copy of an ArrayRef.
+ *
+ * This makes it convenient, clear, and performant (the compiler will
+ * either do RVO to elide the temporary, or invoke the move constructor
+ * taking the unnamed temporary) to write a declaration like
+ *
+ * auto v = copyOf(arrayRef);
+ *
+ * \ingroup module_utility
+ */
+template <typename T>
+std::vector<T> copyOf(const ArrayRef<const T> &arrayRef)
+{
+ return std::vector<T>(arrayRef.begin(), arrayRef.end());
+}
+
} // namespace gmx
#endif