Beyond the C++ Standard Library: An Introduction to Boost [Electronic resources]

Bjorn Karlsson

نسخه متنی -صفحه : 124/ 44
نمايش فراداده

Utility Summary

This chapter has demonstrated some useful utility classes that can greatly simplify our daily life. BOOST_STATIC_ASSERT asserts at compile time, which is very helpful both for testing preconditions and enforcing other requirements. For generic programming, checked_delete is extremely helpful in detecting erroneous usage, which in turn can save a lot of time reading terribly verbose error messages and studying code that seems just fine. We have also covered addressof, which is a handy tool for getting to the real address of an object, regardless of what operator& says. We also saw how enable_if and disable_if can control which functions participate in overload resolution and learned what SFINAE means!

We talked about the base class noncopyable. By providing both a useful idiom and straightforward usage that catches the eye of anyone reading the code, it definitely deserves to be used regularly. The omission of a copy constructor and assignment operator in classes that need them, whether through the need for customized copying/assignment or the prohibition thereof, is all too common in code, costing lots of frustration, time, and money.

This is one of the shortest chapters in the book, and I suspect that you've read through it fairly quickly. It pays you back fast, too, if you start using these utilities right away. There are other utilities in Boost.Utility, which I haven't covered here. You might want to surf over to the Boost Web site and have a look at the online documentation to see what other handy tools there would suit you well in your current work.