C++ (Qt)template <class T>size_t LookupNearby( const std::vector <T> & vec, double value ){ size_t index = 0; size_t i, limit = vec.size(); for (i = 1; i < limit; ++i) if (fabs(vec[i] - value) < fabs(vec[index] - value)) index = i; return index;}