Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
template<typename Value>
std::vector<std::pair<double, Value>> make_intervals(
std::vector<Weighted<Value>> const& weighted_values)
{
std::vector<std::pair<double, Value>> intervals;
intervals.reserve(weighted_values.size());
double summed_weights = 0.0;
for (auto const& weighted_value: weighted_values)
{
summed_weights += weighted_value.m_weight;
intervals.emplace_back(summed_weights, weighted_value.m_value);
}
return intervals;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment