Created
May 27, 2016 05:43
-
-
Save tenomoto/17ff04f4a1445302bb19a439c8c2546b to your computer and use it in GitHub Desktop.
Find index of the first element larger or equal to a given value in C++
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 <iterator> | |
#include <algorithm> | |
template <typename Iter, typename T> | |
size_t find_index(Iter begin, Iter end, T x0) | |
{ | |
return std::distance(begin, std::find_if(begin, end, [x0](double x){return x >= x0;})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment