MFC is a "legacy" framework and was created long before modern C++ features were available. So asking if CArray
is deprecated, to me, is sort of like asking if C's malloc
should be used in code anymore. In general I'd say don't use it for new development but if it is working in existing code then why bother changing it.
Do be aware that it doesn't work properly with some types. If you are either in this case or you don't have control over what is getting inserted into the array then it might make sense to switch to a STL vector instead. If nothing else STL's vector is better performant, more secure and more modern so there are gains here.
At the same time, you're dealing with established code and there may be places in your code, or MFC, where CArray
is expected. In those cases sticking with CArray
would make more sense. Of course if it is your code then you might be able to just swap out the types using grep. Not sure what members you're using that may not be on the STL vector though. Furthermore the behavior may be different at runtime so you'd need to fully test your changes to ensure everything is behaving the same. But calls into MFC that require a CArray
are going to require a conversion so if you're working with very large arrays then the conversion cost may be too high and sticking with CArray
may be better.
If you're dealing with a very large codebase and you are relying on functionality not in STL vector then you could create your own wrapper class that uses CArray
under the hood and exposes the same functionality. Then globally replace the usage of CArray
. Finally you could migrate your wrapper to STL vector and implement the underlying CArray-only logic using the vector. This is a lot more work to me but it is a middle ground when dealing with large codebases. Once you have things working with the new implementation then you can begin swapping out uses of your wrapper class with a regular STL vector and either create helper functions to handle the CArray-only functionality or leave them with your wrapper class.