A few readers have left comments on my Windows with C++ column for July 2011. I was hoping to respond but there is a problem with the commenting infrastructure that prevents me from leaving a comment. If you missed it, you can read it online now.
In this issue, I introduce the unique_handle class template. Here are a few questions I received along with my answers.
Juan Carlos Trimiño asks about the empty throw exception specification as it relates to Boost and Visual C++.
Boost is designed to work with a large variety of C++ compilers. The Windows with C++ column is about Windows and Visual C++. You can of course use the techniques I illustrate with other compilers but you may need to optimize certain practices for your compiler of choice. The Visual C++ compiler will in all likelihood inline all of the functions in the unique_handle class template in which case the throw specification would have no effect. I prefer not to base too many coding decisions on whether or not a function will be inlined. I do not want to take any chances as the performance impact on large code bases can be significant. In the future we will be able to use “noexcept” from C++0x as a more portable and semantically correct way of expressing the same thing.
DavidTM asks about the relevance of the Windows API in today’s world of MFC, .NET and C#.
Libraries like MFC and to a lesser degree ATL are very old. I first learned how to use MFC when I was in my teens. It was designed around an early version of C++ that is not representative of modern C++ style. You can of course still use MFC but I do not recommend it as modern C++ can do a better job of supporting the Windows developer. As for .NET, that is a choice you need to make weighing up your experience, the level of productivity and assistance you expect, and your performance requirements. See my interview for more on this.
Juan Carlos Trimiño asks another question about auto_ptr.
C++0x introduces the unique_ptr class template that completely replaces the older auto_ptr class template. You should never again use auto_ptr for anything. If you need an STL container of pointers then use unique_ptr.