是否允许指针作为有序STL容器中的键? [英] Are pointers allowed as keys in ordered STL containers?

查看:79
本文介绍了是否允许指针作为有序STL容器中的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关这个问题要问如何比较指针应该如何解释的问题,请参阅C ++ Std。

There's this other question asking about how comparing pointers is supposed to be interpreted wrt the C++ Std.

所以我想知道C ++ Std在有序标准库(STL)容器中使用指针作为键是什么 - 即允许有

So I was wondering what the C++ Std has to say about using pointers as keys in ordered standard library (STL) containers -- i.e. is one allowed to have

std :: map< T1 *,T2>

std :: less 内置操作符

推荐答案

是的,因为它使用 std :: less ,这是必要的, code>< 不。 (< 将允许将来自不同序列的不同指针视为相等,这将导致 map etc,如果你插入来自不同序列的指针)。

Yes, because it uses std::less, which is required to result in a total order even if < doesn't. (< would be allowed to treat different pointers from distinct sequences as equal, which would result in an odd behaviour of map etc if you insert pointers from different sequences).

这篇关于是否允许指针作为有序STL容器中的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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