diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-01-24 17:43:37 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-02-15 13:28:50 (GMT) |
commit | 1cecd3a53107f7f670cf011201c1da3a33b795b6 (patch) | |
tree | c51c2b1aaa9eaf8c8ad1755ea72da2a9f6b68b5c /Source/cmListCommand.cxx | |
parent | be3d4b665f27b9ea301540d5bf8154491ed815e0 (diff) | |
download | CMake-1cecd3a53107f7f670cf011201c1da3a33b795b6.zip CMake-1cecd3a53107f7f670cf011201c1da3a33b795b6.tar.gz CMake-1cecd3a53107f7f670cf011201c1da3a33b795b6.tar.bz2 |
cmListCommand: Use std::find algorithm for FIND subcommand.
Use a ostringstream to account for the input being a variable of type
size_t as a result of using std::distance. There is no single
format string which portably accepts a size_t.
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r-- | Source/cmListCommand.cxx | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index dd0cfa9..ae13fdf 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -284,18 +284,14 @@ bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args) return true; } - std::vector<std::string>::iterator it; - unsigned int index = 0; - for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it ) + std::vector<std::string>::iterator it = + std::find(varArgsExpanded.begin(), varArgsExpanded.end(), args[2]); + if (it != varArgsExpanded.end()) { - if ( *it == args[2] ) - { - char indexString[32]; - sprintf(indexString, "%d", index); - this->Makefile->AddDefinition(variableName, indexString); - return true; - } - index++; + std::ostringstream indexStream; + indexStream << std::distance(varArgsExpanded.begin(), it); + this->Makefile->AddDefinition(variableName, indexStream.str().c_str()); + return true; } this->Makefile->AddDefinition(variableName, "-1"); |