Created
June 3, 2013 17:15
-
-
Save mkamotsu/5699673 to your computer and use it in GitHub Desktop.
std::min_elementで0でない最小値を見つけるための比較関数 ref: http://qiita.com/items/bd65c5473f5ef238d9cd
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 = {0, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 0}; | |
auto min = min_element(a.begin(), a.end(), [](int a, int b) { | |
return (a == 0) ? false : (b == 0) || a < b; | |
}); | |
cout << *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