null_deleter.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2014.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file null_deleter.hpp
  9. * \author Andrey Semashev
  10. * \date 22.04.2007
  11. *
  12. * This header contains a \c null_deleter implementation. This is an empty
  13. * function object that receives a pointer and does nothing with it.
  14. * Such empty deletion strategy may be convenient, for example, when
  15. * constructing <tt>shared_ptr</tt>s that point to some object that should not be
  16. * deleted (i.e. a variable on the stack or some global singleton, like <tt>std::cout</tt>).
  17. */
  18. #ifndef BOOST_CORE_NULL_DELETER_HPP
  19. #define BOOST_CORE_NULL_DELETER_HPP
  20. #include <boost/config.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. //! A function object that does nothing and can be used as an empty deleter for \c shared_ptr
  26. struct null_deleter
  27. {
  28. //! Function object result type
  29. typedef void result_type;
  30. /*!
  31. * Does nothing
  32. */
  33. template< typename T >
  34. void operator() (T*) const BOOST_NOEXCEPT {}
  35. };
  36. } // namespace boost
  37. #endif // BOOST_CORE_NULL_DELETER_HPP