local_sp_deleter.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ) noexcept: d_( d )
  31. {
  32. }
  33. explicit local_sp_deleter( D&& d ) noexcept: d_( std::move(d) )
  34. {
  35. }
  36. D& deleter() noexcept
  37. {
  38. return d_;
  39. }
  40. template<class Y> void operator()( Y* p ) noexcept
  41. {
  42. d_( p );
  43. }
  44. void operator()( std::nullptr_t p ) noexcept
  45. {
  46. d_( p );
  47. }
  48. };
  49. template<> class local_sp_deleter<void>
  50. {
  51. };
  52. template<class D> D * get_local_deleter( local_sp_deleter<D> * p ) noexcept
  53. {
  54. return &p->deleter();
  55. }
  56. inline void * get_local_deleter( local_sp_deleter<void> * /*p*/ ) noexcept
  57. {
  58. return 0;
  59. }
  60. } // namespace detail
  61. } // namespace boost
  62. #endif // #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_SP_DELETER_HPP_INCLUDED