#include <algorithm>
#include <iostream>
#include <vector>

std::size_t getIndexFor(const std::vector<int>& v, int input)
{
    auto it = std::find_if(v.begin(), v.end(), [&](int e){ return e > input;});
    if (it == v.begin()) {
        throw std::runtime_error("input not handled");
    }
    --it;
    return std::distance(v.begin(), it);
}

int main()
{
    const std::vector<int> v = { 0, 2, 4, 5};

    for (int i : {0, 1, 2, 3, 4, 5}) {
        std::cout << getIndexFor(v, i) << ":" << i << std::endl;
    }
}
