返回地图的 map::lower_bound

发布于 2024-09-01 09:12:57 字数 162 浏览 1 评论 0原文

是否有一个函数与 map::lower_bound 执行相同的操作,只是它返回一个新的子映射而不是迭代器?

编辑:该函数应返回一个子映射,其中包含键等于或大于某个值(作为输入给出的所有值)的函数)。

Is there a function that does the same thing as map::lower_bound except it returns a new sub-map and not an iterator?

Edit: The function should return a sub-map which contains all the values for which the key is equal to, or greater than a certain value (which is given as input to the function).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-09-08 09:12:57

像这样的东西吗?

// Beware, brain-compiled code ahead!
template< typename K, typename V >
std::map<K,V> equal_or_greater(const std::map<K,V>& original, const K& k)
{
   return std::map<K,V>( original.lower_bound(k), original.end() );
}

编辑:看来您实际上想要upper_bound()而不是lower_bound()

Something like this?

// Beware, brain-compiled code ahead!
template< typename K, typename V >
std::map<K,V> equal_or_greater(const std::map<K,V>& original, const K& k)
{
   return std::map<K,V>( original.lower_bound(k), original.end() );
}

Edit: It seems you actually want upper_bound() instead of lower_bound().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文