local_sp_deleter.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_SP_DELETER_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_LOCAL_SP_DELETER_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // detail/local_sp_deleter.hpp
  8. //
  9. // Copyright 2017 Peter Dimov
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See
  12. // accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. //
  15. // See http://www.boost.org/libs/smart_ptr/ for documentation.
  16. #include <boost/smart_ptr/detail/local_counted_base.hpp>
  17. #include <boost/config.hpp>
  18. namespace boost
  19. {
  20. namespace detail
  21. {
  22. template<class D> class local_sp_deleter: public local_counted_impl_em
  23. {
  24. private:
  25. D d_;
  26. public:
  27. local_sp_deleter(): d_()
  28. {
  29. }
  30. explicit local_sp_deleter( D const& d ) BOOST_SP_NOEXCEPT: d_( d )
  31. {
  32. }
  33. #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
  34. explicit local_sp_deleter( D&& d ) BOOST_SP_NOEXCEPT: d_( std::move(d) )
  35. {
  36. }
  37. #endif
  38. D& deleter() BOOST_SP_NOEXCEPT
  39. {
  40. return d_;
  41. }
  42. template<class Y> void operator()( Y* p ) BOOST_SP_NOEXCEPT
  43. {
  44. d_( p );
  45. }
  46. #if !defined( BOOST_NO_CXX11_NULLPTR )
  47. void operator()( boost::detail::sp_nullptr_t p ) BOOST_SP_NOEXCEPT
  48. {
  49. d_( p );
  50. }
  51. #endif
  52. };
  53. template<> class local_sp_deleter<void>
  54. {
  55. };
  56. template<class D> D * get_local_deleter( local_sp_deleter<D> * p ) BOOST_SP_NOEXCEPT
  57. {
  58. return &p->deleter();
  59. }
  60. inline void * get_local_deleter( local_sp_deleter<void> * /*p*/ ) BOOST_SP_NOEXCEPT
  61. {
  62. return 0;
  63. }
  64. } // namespace detail
  65. } // namespace boost
  66. #endif // #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_SP_DELETER_HPP_INCLUDED