Why STL containers are preferred over MFC containers?

c++, containers, mfc, stl

Solution

Ronald Laeremans, VC++ Product Unit Manager, even said to use STL in June 2006:

And frankly the team will give you the same answer. The MFC collection classes are only there for backwards compatibility. C++ has a standard for collection classes and that is the Standards C++ Library. There is no technical drawback for using any of the standard library in an MFC application.

We do not plan on making significant changes in this area.

Ronald Laeremans Acting Product Unit Manager Visual C++ Team

However, at one point where I was working on some code that ran during the installation phase of Windows, I was not permitted to use STL containers, but was told to use ATL containers instead (actually `CString` in particular, which I guess isn't really a container). The explanation was that the STL containers had dependecies on runtime bits that might not actually be available at the time the code had to execute, while those problems didn't exist for the ATL collections. This is a rather special scenario that shouldn't affect 99% of the code out there.

Problem

Previously, I used to use MFC collection classes such `CArray` and `CMap`. After a while I switched to STL containers and have been using them for a while. Although I find STL much better, I am unable to pin point the exact reasons for it. Some of the reasoning such as : - It requires MFC: does not hold because other parts of my program uses MFC - It is platform dependent: does not hold because I run my application only on windows.(No need for portability) - It is defined in the C++ standard: OK, but MFC containers still work The only reason I could come up is that I can use algorithms on the containers. Is there any other reason that I am missing here - what makes STL containers better than MFC containers?

Original source