Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active April 29, 2017 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/7f58dabc6b09686e0354964a445ccbaf to your computer and use it in GitHub Desktop.
Save deque-blog/7f58dabc6b09686e0354964a445ccbaf to your computer and use it in GitHub Desktop.
template<typename Value>
Value search_containing_interval(
std::vector<std::pair<double, Value>> const& intervals, double weight)
{
auto it = std::lower_bound(
intervals.begin(), intervals.end(), weight,
[](auto const& element, double weight)
{
return element.first < weight;
});
return it->second; //By construction, always exists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment