Skip to content

Instantly share code, notes, and snippets.

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