enable_shared_from.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/enable_shared_from_this.hpp>
  13. namespace boost
  14. {
  15. class enable_shared_from: public enable_shared_from_this<enable_shared_from>
  16. {
  17. private:
  18. using enable_shared_from_this<enable_shared_from>::shared_from_this;
  19. using enable_shared_from_this<enable_shared_from>::weak_from_this;
  20. };
  21. template<class T> shared_ptr<T> shared_from( T * p )
  22. {
  23. return shared_ptr<T>( p->enable_shared_from_this<enable_shared_from>::shared_from_this(), p );
  24. }
  25. template<class T> weak_ptr<T> weak_from( T * p ) noexcept
  26. {
  27. return weak_ptr<T>( p->enable_shared_from_this<enable_shared_from>::weak_from_this(), p );
  28. }
  29. } // namespace boost
  30. #endif // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED