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.
This commit is contained in:
Stephen Kelly 2015-01-24 18:43:37 +01:00
parent be3d4b665f
commit 1cecd3a531
1 changed files with 7 additions and 11 deletions

View File

@ -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");