看起来很简单,std :: find的典型用法
for ( auto element : generic->vec() )
LOG << element;
LOG << channel;
if ( !gen->vec().empty() ) {
if(std::find(generic->vec().begin(), generic->vec().end(), channel) != generic->vec().end()){
LOG << "Found";
;// Found the item
} else {
LOG << "Not Found";
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
请检查日志文件
2018-11-08, 09:37:18 [INFO] - [140455150589696] - 1
2018-11-08, 09:37:18 [INFO] - [140455150589696] - 2
2018-11-08, 09:37:18 [INFO] - [140455150589696] - 4
2018-11-08, 09:37:18 [INFO] - [140455150589696] - 12
2018-11-08, 09:37:18 [INFO] - [140455150589696] - 40 …Run Code Online (Sandbox Code Playgroud) 这段c ++代码无法编译。有人知道为什么吗?
#include <functional>
#include <algorithm>
#include <vector>
#include <iostream>
int main(int a, char** v) {
std::vector<uint32_t> v1 {1,2,3,4};
std::vector<uint32_t> v2 {0};
std::vector<uint32_t> v3 {5,4,3,11};
std::vector<uint32_t> v4 {10,11,2};
auto vector_is_subset = [] (const std::vector<uint32_t> a, const std::vector<uint32_t> b) -> bool {
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
return std::includes(a.begin(), a.end(), b.begin(), b.end());
};
std::vector<uint32_t> f {};
if (v1.empty() || v2.empty() || v3.empty() || v4.empty() ){
std::cout << "a vector is empty" << std::endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出
g ++ a.cpp -std …