且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

迭代 C++ 映射中的键

更新时间:2022-06-27 01:10:05

如果您确实需要隐藏真实"迭代器返回的值(例如,因为您想使用具有标准算法的密钥迭代器,以便它们对键而不是对进行操作),然后看看 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 :-)]