Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

An Example that Omits Destructor Calls For Types with Trivial Destructors

Demonstrates a simple algorithm that uses __has_trivial_destruct to determine whether to destructors need to be called (see trivial_destructor_example.cpp):

//
// algorithm destroy_array:
// The reverse of std::unitialized_copy, takes a block of
// initialized memory and calls destructors on all objects therein.
//

namespace detail{

template <class T>
void do_destroy_array(T* first, T* last, const boost::false_type&)
{
   while(first != last)
   {
      first->~T();
      ++first;
   }
}

template <class T>
inline void do_destroy_array(T* first, T* last, const boost::true_type&)
{
}

} // namespace detail

template <class T>
inline void destroy_array(T* p1, T* p2)
{
   detail::do_destroy_array(p1, p2, ::boost::has_trivial_destructor<T>());
}

PrevUpHomeNext