-1
私がhereから読むtd::search
述語を理解しようとしています。私は便宜のために以下に掲載しました。std :: search述語を理解する
#include <algorithm>
#include <string>
#include <cctype>
// haystack=Hello and needle=World
/// Try to find in the Haystack the Needle - ignore case
bool findStringIC(const std::string & strHaystack, const std::string & strNeedle)
{
auto it = std::search(
strHaystack.begin(), strHaystack.end(),
strNeedle.begin(), strNeedle.end(),
[](char ch1, char ch2) {
std::cout << ch1 << "?" << ch2 << "\n";
return std::toupper(ch1) == std::toupper(ch2);
}
);
return (it != strHaystack.end());
}
本質的に私はそれ(述語)がどのように機能するのか混乱します。干し草が単語Hello
であり、針が単語World
であると仮定する。今、私が観察したものから、針の最初の文字は、干し草の山のすべての文字に比べて取得することである - ので、W
比べてしまいますL
その後、E
その後、H
に....そう
これと25回の比較は何ですか? –
この述語がどのように機能しているのか、私の理解は間違っていますか? – MistyD
いいえ、それは 'std :: search'の仕組みではありません。 –