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