std :: find未按照我的预期进行评估。std :: find未按预期运行
我有一个向量lexeme_定义为
static const std::string delimiters_[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
static std::vector<std::string> lexeme_(std::begin(delimiters_), std::end(delimiters_));
我以类似于COMMANDLINE有使用被定义为
while (std::find(lexeme_.begin(),lexeme_.end(),std::string(&commandLine_.at(position_))) == lexeme_.end())
{
// Concat each successive alphanumeric character to 'token'
token += commandLine_.at(position_);
// Update the index into 'commandLine'
position_ += 1;
}
评价std::find
应该一char
在lexeme_比较进行评估,以一个char
此Java表达式
!lexeme.contains(Character.toString(commandLine.charAt(position)))
评估应该比较char
s,如果它确定在中的char
在比较中得到满足,则while循环将退出。
测试用例
#include<algorithm>
#include<iostream>
static const std::string delimiters_[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
static std::vector<std::string> lexeme_(std::begin(delimiters_), std::end(delimiters_));
std::string commandLine = "check me";
while (std::find(lexeme_.begin(),lexeme_.end(),std::string(&commandLine_.at(position_))) == lexeme_.end())
{
std::cout "I should stop printing when encountering a space ' ' << std::endl;
}
你可以构建一个完整的测试用例来证明这一点? – 2013-04-08 21:30:52
@DrewDormann需要引用。如上所述,这是可笑的。这当然不是“确实”更快。 – sehe 2013-04-08 21:33:29
那么问题是什么?这段代码做了什么,你期望它做什么,它做的与你期望的做法有什么不同?总之,http://whathaveyoutried.com/ – jalf 2013-04-08 21:34:35