Skip to content

Instantly share code, notes, and snippets.

@mkamotsu
Created June 3, 2013 17:15
Show Gist options
  • Save mkamotsu/5699673 to your computer and use it in GitHub Desktop.
Save mkamotsu/5699673 to your computer and use it in GitHub Desktop.
std::min_elementで0でない最小値を見つけるための比較関数 ref: http://qiita.com/items/bd65c5473f5ef238d9cd
#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;
}
if (comp(*first, *smallest)) {
smallest = first;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment