enable_shared_from.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED
  3. // enable_shared_from.hpp
  4. //
  5. // Copyright 2019, 2020 Peter Dimov
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt
  10. //
  11. // See http://www.boost.org/libs/smart_ptr/ for documentation.
  12. #include <boost/smart_ptr/detail/requires_cxx11.hpp>
  13. #include <boost/smart_ptr/enable_shared_from_this.hpp>
  14. #include <boost/smart_ptr/detail/sp_noexcept.hpp>
  15. namespace boost
  16. {
  17. class enable_shared_from: public enable_shared_from_this<enable_shared_from>
  18. {
  19. private:
  20. using enable_shared_from_this<enable_shared_from>::shared_from_this;
  21. using enable_shared_from_this<enable_shared_from>::weak_from_this;
  22. };
  23. template<class T> shared_ptr<T> shared_from( T * p )
  24. {
  25. return shared_ptr<T>( p->enable_shared_from_this<enable_shared_from>::shared_from_this(), p );
  26. }
  27. template<class T> weak_ptr<T> weak_from( T * p ) BOOST_SP_NOEXCEPT
  28. {
  29. return weak_ptr<T>( p->enable_shared_from_this<enable_shared_from>::weak_from_this(), p );
  30. }
  31. } // namespace boost
  32. #endif // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED