哪些 STL 容器需要使用 CAdapt?

发布于 2024-08-15 07:01:09 字数 589 浏览 4 评论 0原文

CAdapt 类由 Microsoft 提供为了能够使用覆盖 STL 容器中运算符 (operator&) 地址的类。 MSDN 关于 CAdapt 的使用是这样说的:

通常,当您想要存储 CComBSTRCComPtrCComQIPtrCComQIPtr 时,您将使用 CAdapt STL 容器中的 code>_com_ptr_t 对象,例如 list

关于我的问题:

应该使用 CAdapt 的 STL 容器的完整列表是什么?

如果容器包含键/值对(例如 map)请指定键或值是否需要CAdapt

The CAdapt class is provided by Microsoft in order to enable using classes that override the address of operator (operator&) in STL containers. MSDN has this to say about the use of CAdapt:

Typically, you will use CAdapt when you want to store CComBSTR, CComPtr, CComQIPtr, or _com_ptr_t objects in an STL container such as a list.

On to my quesiton:

What is the full list of STL containers with which CAdapt should be used?

If the container contains a key/value pair (such as map) please specify whether CAdapt is needed for the key or the value.

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

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

发布评论

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

评论(2

客…行舟 2024-08-22 07:01:09

应使用 CAdapt 的 STL 容器的完整列表是什么?

没有任何。实现应假设运算符&已重载,并使用正确的表达式 &reinterpret_cast(obj)

现在,还有一个您没有问的问题:

我的 VC++ STL 实现不同意。它确实提供了 CAdapt 作为解决方法。应该使用 CAdapt 的容器的完整列表是什么?

在我的脑海中,我会使用 vector (将它们存储为 T[] 因此合理地需要对它们进行算术)和 deque (将它们存储为多个更小的T[] 的原理相同)。 list、map、set、multiset 和 multimap 都在节点上工作,因此它们本身已经包装了每个对象。

What is the full list of STL containers with which CAdapt should be used?

None. Implementations should assume operator& is overloaded, and use the correct expression &reinterpret_cast<char&>(obj)

Now, there is another question that you didn't ask:

My VC++ STL implementation doesn't agree. It does provide CAdapt as a workaround. What is the full list of its containers with which CAdapt should be used?

Top of my head, I'd day vector<T> (stores them as a T[] so reasonably needs arithmetic on them) and deque (stores them as multiple smaller T[]s so same rationale). list, map, set, multiset and multimap all work on nodes, so they themselves already wrap each object.

不气馁 2024-08-22 07:01:09

文档中的另一件事:

适配器类 CAdapt 很有用,因为许多容器类(例如 STL 容器类)期望能够使用 address-of 运算符获取其所包含对象的地址。strong 文本。

我认为您不会找到具有此要求的容器列表。这听起来像是实施依赖于我。

Another thing from documentation:

The adapter class CAdapt is useful because many container classes (such as the STL container classes) expect to be able to obtain the addresses of their contained objects using the address-of operator.strong text.

I don't think you'll find a list of containers that have this requirement. This sounds like implementation dependent to me.

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