Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Created May 27, 2016 05:43
Show Gist options
  • Save tenomoto/17ff04f4a1445302bb19a439c8c2546b to your computer and use it in GitHub Desktop.
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++
#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