I would like to securely clear (in simple case, setting contents to zeros) sensitive information from memory stored by std::string and std::vector elements. My vector can contain also primitive types (like std::vector) so I guess it would be more convenient to do clearing of all contained elements inside destructor of vector because primite types don't have destructor. I can't override std::string and std::vector classes with inheritance because those types are not designed for that (no virtual destructor, etc). Is there any other way? I found some posts with std::string automatic clearing but sample implementations there were all incomplete. Currently I clear my objects by manually setting contents to zeros when finished using object but that is very tedious.
Edit: Also clearing memory in this way is not secure as C++ containers could allocate/deallocate memory during some operations. That's why using allocators (described in similar question) could be only way to do that at least for longer strings where SSO (Short String Optimization) is not used.