迭代 C++ 映射中的键 [英] Iterate keys in a C++ map

查看:29
本文介绍了迭代 C++ 映射中的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法迭代键而不是 C++ 映射对?

Is there a way to iterate over the keys, not the pairs of a C++ map?

推荐答案

如果您确实需要隐藏真实"迭代器返回的值(例如,因为您想使用具有标准算法的密钥迭代器,以便它们对键而不是对进行操作),然后看看 Boost 的 transform_iterator.

If you really need to hide the value that the "real" iterator returns (for example because you want to use your key-iterator with standard algorithms, so that they operate on the keys instead of the pairs), then take a look at Boost's transform_iterator.

[提示:查看新类的 Boost 文档时,请先阅读末尾的示例".然后,您就有机会弄清楚其余部分到底在谈论什么:-)]

[Tip: when looking at Boost documentation for a new class, read the "examples" at the end first. You then have a sporting chance of figuring out what on earth the rest of it is talking about :-)]

这篇关于迭代 C++ 映射中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆