The prescribed solution to this problem is to not place the COM types directly into the STL container but instead wrap them with the ATL CAdapt class. When adopting this approach there are two important aspects to consider:
- Firstly, is there a way to prevent incorrect usage of the containers?
- Secondly, assuming this is possible, is there a way to make sure it covers the various permutations of STL containers and COM types that are being used?
It turns out that the first issue is easily solved using template specialization. The hard part though is creating a set of unit tests that ensure specializations have been created for all permutations and that they are active. This is made even more difficult by the fact a successful use of the specialization results in compilation failure.
This too can be solved by combing various template mechanisms and techniques: SFINAE & Template Meta-programming etc. In the April issue of the ACCU Overload journal I have written article that describes this problem along with the solution. Please follow the link below (and then jump to page 24 in the PDF if it doesn't open there automatically).
http://accu.org/var/uploads/journals/overload108.pdf#page=24
The complete source code the article is also available on GitHut: https://github.com/petebarber/TemplateArticleExamples
3 comments:
You can use a URL as the following to directly jump to the desired page:
http://accu.org/var/uploads/journals/overload108.pdf#page=24
Cheers,
Martin
Thanks for the tip Martin. Post updated.
Interesting technique and a very good article.
Post a Comment