mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
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);
}
}
```
This commit is contained in:
@@ -25,15 +25,13 @@ bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// expand the variable
|
||||
std::vector<std::string> varArgsExpanded;
|
||||
cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
|
||||
std::vector<std::string> const varArgsExpanded =
|
||||
cmSystemTools::ExpandedListArgument(cacheValue);
|
||||
|
||||
// expand the args
|
||||
// check for REMOVE(VAR v1 v2 ... vn)
|
||||
std::vector<std::string> argsExpanded;
|
||||
std::vector<std::string> temp;
|
||||
temp.insert(temp.end(), args.begin() + 1, args.end());
|
||||
cmSystemTools::ExpandList(temp, argsExpanded);
|
||||
std::vector<std::string> const argsExpanded =
|
||||
cmSystemTools::ExpandedLists(args.begin() + 1, args.end());
|
||||
|
||||
// now create the new value
|
||||
std::string value;
|
||||
|
||||
Reference in New Issue
Block a user