forked from keineahnung2345/cpp-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_if.cpp
More file actions
21 lines (17 loc) · 726 Bytes
/
Copy pathfind_if.cpp
File metadata and controls
21 lines (17 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <vector>
#include <iostream>
//https://stackoverflow.com/questions/12990148/get-all-positions-of-elements-in-stl-vector-that-are-greater-than-a-value
//find the index that meets a requirement
int main(){
std::vector<int> myvec = {1, 3, 2, 7, 4, 9, 5};
std::vector<size_t> results;
auto it = std::find_if(std::begin(myvec), std::end(myvec), [](int i){return i > 5;});
while (it != std::end(myvec)) {
results.emplace_back(std::distance(std::begin(myvec), it));
it = std::find_if(std::next(it), std::end(myvec), [](int i){return i > 5;});
}
std::copy(results.begin(), results.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
return 0;
}
//3 5