Created
June 3, 2013 17:02
-
-
Save mkamotsu/5699608 to your computer and use it in GitHub Desktop.
std::min_elementで0でない最小値を探すための比較関数 ref: http://qiita.com/items/e7918d3416c5ae6a1102
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using std::vector; | |
using std::cout; | |
using std::endl; | |
int main() { | |
vector<int> a = {5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5}; | |
auto min = min_element(a.begin(), a.end(), [](int a, int b) { | |
return ((a != 0) && (b == 0)) || a < b; | |
}); | |
cout << distance(a.begin(), min) << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (comp(*first, *smallest)) { | |
smallest = first; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment