codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <iterator> #include <algorithm> struct xyz { int a; int b; }; bool findit(const xyz& a) { return (a.a == 2 && a.b == 3); } int main() { xyz begin[] = { {1, 2}, {2, 3}, {2, 3}, {3, 5} }; xyz* end = begin + 4; // Forward find xyz* found = std::find_if(begin, end, findit); if (found != end) std::cout << "Found at position " << found - begin << std::endl; // Reverse find found = std::find_if(std::reverse_iterator<xyz*>(end), std::reverse_iterator<xyz*>(begin), findit); if (found != std::reverse_iterator<xyz*>(end)); std::cout << "Found at position " << found - std::reverse_iterator<xyz*>(end) << std::endl; return 0; }
Private
[
?
]
Run code
Submit