How Does the Utility Library Improve Your Programs?


  • Compile time assertions with BOOST_STATIC_ASSERT

  • Safe destruction with checked_delete and checked_array_delete

  • Prohibition of copying with noncopyable

  • Retrieval of object addresses when operator& is overloaded through addressof

  • Controlled participation of overloads and specializations with enable_if and disable_if

There are some utilities that just don't constitute a library in their own right, and are therefore grouped together with other entities. This is what Boost.Utility is, a collection of useful tools with no better home. They are useful enough to warrant inclusion in Boost, yet they are too small to deserve their own library. This chapter covers some of Boost.Utility's most fundamental and widely applicable tools.

We'll start with BOOST_STATIC_ASSERT, a facility for asserting integral constant expressions at compile time. Then, we'll see what happens when you delete an object through a pointer to an incomplete typethat is, when the layout of the object being destroyed is unknown. checked_delete makes that discussion more interesting. We'll also see how noncopyable prevents a class from ever being copied, which is arguably the most important topic of this chapter. Then, we'll check out addressof, which defeats the ill doings of menacing programmers[1] who overload operator&. Finally, we shall examine enable_if, which is really useful for controlling whether function overloads and template specializations are considered during name lookup or not.

[1] If you feel that I'm out of line here, please send me your most compelling use cases for overloading operator&.



    Beyond the C++ Standard Library(c) An Introduction to Boost
    Beyond the C++ Standard Library: An Introduction to Boost
    ISBN: 0321133544
    EAN: 2147483647
    Year: 2006
    Pages: 125

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net