本文整理匯總了C++中std::equal方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::equal方法的具體用法?C++ std::equal怎麽用?C++ std::equal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::equal方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: get_paths_from_dir
bool sensor_plugin_loader::get_paths_from_dir(const string &dir_path, vector<string> &hal_paths, vector<string> &sensor_paths)
{
const string PLUGIN_POSTFIX = ".so";
const string HAL_POSTFIX = "_hal.so";
DIR *dir = NULL;
struct dirent *dir_entry = NULL;
dir = opendir(dir_path.c_str());
if (!dir) {
ERR("Failed to open dir: %s", dir_path.c_str());
return false;
}
string name;
while (dir_entry = readdir(dir)) {
name = string(dir_entry->d_name);
if (equal(PLUGIN_POSTFIX.rbegin(), PLUGIN_POSTFIX.rend(), name.rbegin())) {
if (equal(HAL_POSTFIX.rbegin(), HAL_POSTFIX.rend(), name.rbegin()))
hal_paths.push_back(dir_path + "/" + name);
else
sensor_paths.push_back(dir_path + "/" + name);
}
}
closedir(dir);
return true;
}
示例2: main
int main(int argc, char* argv[]) {
// 3
// 2 5
// 1 4 6
unique_ptr<BinaryTreeNode<int>> root = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{3, nullptr, nullptr});
root->left = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{2, nullptr, nullptr});
root->left->left = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{1, nullptr, nullptr});
root->right = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{5, nullptr, nullptr});
root->right->left = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{4, nullptr, nullptr});
root->right->right = unique_ptr<BinaryTreeNode<int>>(
new BinaryTreeNode<int>{6, nullptr, nullptr});
// should output 3
// 2 5
// 1 4 6
PrintBinaryTreeDepthOrder(root);
vector<vector<int>> golden_res = {{3}, {2, 5}, {1, 4, 6}};
assert(golden_res.size() == results.size() &&
equal(golden_res.begin(), golden_res.end(), results.begin()));
return 0;
}
示例3: test
void MorphemeDisambiguatorClass::test(const string &testFilename) const {
ifstream ifs(testFilename);
size_t correctCount = 0;
size_t allCount = 0;
while (true) {
vector<string> sequence = Utility::readSequence(ifs);
if (!ifs) {
break;
}
vector<string> sentence;
vector<vector<string>> correctResultList;
splitSentenceAndResult(sequence, &sentence, &correctResultList);
auto inferredResultList = tag(sentence);
assert(inferredResultList.size() == correctResultList.size());
for (size_t i = 0; i < inferredResultList.size(); ++i) {
if (inferredResultList[i].size() == correctResultList[i].size() + 2 &&
equal(inferredResultList[i].begin() + 2, inferredResultList[i].end(), correctResultList[i].begin())) {
++correctCount;
}
++allCount;
}
}
ifs.close();
printf("Accuracy: %d / %d (%1.4f)\n", correctCount, allCount, correctCount / (double)allCount);
}
示例4: apply
static bool apply(alps::numeric::matrix<T,MemoryBlock> const& m) {
typedef typename alps::numeric::matrix<T,MemoryBlock>::const_col_element_iterator col_iterator;
using alps::hdf5::get_extent;
using alps::hdf5::is_vectorizable;
using std::equal;
if(boost::is_scalar<typename alps::numeric::matrix<T,MemoryBlock>::value_type>::value || m.empty())
return true;
else {
std::vector<std::size_t> first_element_extent(get_extent(m(0,0)));
for(std::size_t j=0; j < num_cols(m); ++j) {
for(std::pair<col_iterator,col_iterator> r = col(m,j); r.first != r.second; ++r.first) {
if(!is_vectorizable(*r.first)) {
return false;
} else {
std::vector<std::size_t> element_extent(get_extent(*r.first));
if(
first_element_extent.size() != element_extent.size()
|| !equal(first_element_extent.begin(), first_element_extent.end(), element_extent.begin())
)
return false;
}
}
}
return true;
}
}
示例5: src
END_TEST
START_TEST(should_overwrite_destination_file)
{
Process_dir_fixture f;
string src(f.get_path() + "/src");
create_emptyfile(src);
vector<char> content(dummy_content());
write_to_file(src, content);
vector<char> dest_content(content);
dest_content.insert(dest_content.end(), content.begin(), content.end());
random_shuffle(dest_content.begin(), dest_content.end());
string dest(f.get_path() + "/dest");
write_to_file(dest, dest_content);
Io io;
int r(copy(io, src.c_str(), dest.c_str()));
fail_unless(r == 0, "result value");
vector<char> copied;
read_file(dest, copied);
fail_unless(content.size() == copied.size(), "size");
fail_unless(equal(content.begin(), content.end(), copied.begin()),
"value");
}
示例6: is_palindrome
inline bool is_palindrome(string word) { return equal(word.begin(), word.end(), word.rbegin()); }
示例7: is_palindrome
bool is_palindrome(const string& s)
{
return equal(s.begin(), s.end(), s.rbegin());
}