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