null_deleter.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // Block unintended ADL
  26. namespace null_deleter_ns {
  27. //! A function object that does nothing and can be used as an empty deleter for \c shared_ptr
  28. struct null_deleter
  29. {
  30. //! Function object result type
  31. typedef void result_type;
  32. /*!
  33. * Does nothing
  34. */
  35. template< typename T >
  36. void operator() (T*) const BOOST_NOEXCEPT {}
  37. };
  38. } // namespace null_deleter_ns
  39. using null_deleter_ns::null_deleter;
  40. } // namespace boost
  41. #endif // BOOST_CORE_NULL_DELETER_HPP