summaryrefslogtreecommitdiff
path: root/Source/cmSystemTools.h
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-05-12 13:11:51 +0200
committerSebastian Holtermann <sebholt@xwmw.org>2019-05-13 15:37:18 +0200
commitcdff7f4e2a255e083e5a19ac541b4de2874785af (patch)
tree227828817ddbc2cf408564526ba0d315bcf7555e /Source/cmSystemTools.h
parent741fb95f660c73035a26b572dfcd3d628d324d57 (diff)
downloadcmake-cdff7f4e2a255e083e5a19ac541b4de2874785af.tar.gz
cmSystemTools: Add ExpandedListArgument and ExpandedLists methods
Changes ------- In `cmSystemTools` this - renames the method `ExpandList` to `ExpandLists` and makes it iterator based and adds the methods - `std::vector<std::string> ExpandedLists(InputIt first, InputIt last)` - `std::vector<std::string> ExpandedListArgument(const std::string& arg, bool emptyArgs)` Both return the `std::vector<std::string>` instead of taking a return vector reference like `cmSystemTools::ExpandLists` and `cmSystemTools::ExpandListArgument`. Motivation ---------- Since C++17 return value optimization is mandatory, so returning a `std:vector<std::string>` from a function should be (at least) as fast as passing a return vector reference to the function. The new methods can replace `cmSystemTools::ExpandLists` and `cmSystemTools::ExpandListArgument` in many cases, which leads to shorter and simpler syntax. E.g. the commonly used pattern ``` if (const char* value = X->GetProperty("A_KEY_STRING")) { std::vector<std::string> valuesList; cmSystemTools::ExpandListArgument(value, valuesList); for (std::string const& i : valuesList) { doSomething(i); } } ``` becomes ``` if (const char* value = X->GetProperty("A_KEY_STRING")) { for (std::string const& i : cmSystemTools::ExpandedListArgument(value)) { doSomething(i); } } ```
Diffstat (limited to 'Source/cmSystemTools.h')
-rw-r--r--Source/cmSystemTools.h43
1 files changed, 38 insertions, 5 deletions
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 8a87a37861..d145d478b9 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -29,17 +29,50 @@ public:
typedef cmsys::SystemTools Superclass;
typedef cmProcessOutput::Encoding Encoding;
- /** Expand out any arguments in the vector that have ; separated
- * strings into multiple arguments. A new vector is created
- * containing the expanded versions of all arguments in argsIn.
+ /**
+ * Expand the ; separated string @a arg into multiple arguments.
+ * All found arguments are appended to @a argsOut.
*/
- static void ExpandList(std::vector<std::string> const& argsIn,
- std::vector<std::string>& argsOut);
static void ExpandListArgument(const std::string& arg,
std::vector<std::string>& argsOut,
bool emptyArgs = false);
/**
+ * Expand out any arguments in the string range [@a first, @a last) that have
+ * ; separated strings into multiple arguments. All found arguments are
+ * appended to @a argsOut.
+ */
+ template <class InputIt>
+ static void ExpandLists(InputIt first, InputIt last,
+ std::vector<std::string>& argsOut)
+ {
+ for (; first != last; ++first) {
+ cmSystemTools::ExpandListArgument(*first, argsOut);
+ }
+ }
+
+ /**
+ * Same as ExpandListArgument but a new vector is created containing
+ * the expanded arguments from the string @a arg.
+ */
+ static std::vector<std::string> ExpandedListArgument(const std::string& arg,
+ bool emptyArgs = false);
+
+ /**
+ * Same as ExpandList but a new vector is created containing the expanded
+ * versions of all arguments in the string range [@a first, @a last).
+ */
+ template <class InputIt>
+ static std::vector<std::string> ExpandedLists(InputIt first, InputIt last)
+ {
+ std::vector<std::string> argsOut;
+ for (; first != last; ++first) {
+ cmSystemTools::ExpandListArgument(*first, argsOut);
+ }
+ return argsOut;
+ }
+
+ /**
* Look for and replace registry values in a string
*/
static void ExpandRegistryValues(std::string& source,