Which STL containers require the use of 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 storeCComBSTR
,CComPtr
,CComQIPtr
, or_com_ptr_t
objects in an STL container such as alist
.
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 o开发者_运维百科r the value.
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.
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.
精彩评论