views:

191

answers:

2

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.

+1  A: 

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.

Nikola Smiljanić
+2  A: 

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.

MSalters
Except for vector<bool>, which uses a proxy object.
KitsuneYMG
Motti
@Motti: yes, the idea is from ISO C++ WG paper N1324 by Jens Maurer, in response to CWG DR273 (`offsetof` has the same problem).
MSalters