unique_ptr.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-2014. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED
  11. #define BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. #include <boost/move/unique_ptr.hpp>
  22. //!\file
  23. //!This header provides utilities to define a unique_ptr that plays nicely with managed segments.
  24. namespace boost{
  25. namespace interprocess{
  26. //For backwards compatibility
  27. using ::boost::movelib::unique_ptr;
  28. //!Returns the type of a unique pointer
  29. //!of type T with boost::interprocess::deleter deleter
  30. //!that can be constructed in the given managed segment type.
  31. template<class T, class ManagedMemory>
  32. struct managed_unique_ptr
  33. {
  34. typedef boost::movelib::unique_ptr
  35. < T
  36. , typename ManagedMemory::template deleter<T>::type
  37. > type;
  38. };
  39. //!Returns an instance of a unique pointer constructed
  40. //!with boost::interproces::deleter from a pointer
  41. //!of type T that has been allocated in the passed managed segment
  42. template<class T, class ManagedMemory>
  43. inline typename managed_unique_ptr<T, ManagedMemory>::type
  44. make_managed_unique_ptr(T *constructed_object, ManagedMemory &managed_memory)
  45. {
  46. return typename managed_unique_ptr<T, ManagedMemory>::type
  47. (constructed_object, managed_memory.template get_deleter<T>());
  48. }
  49. } //namespace interprocess{
  50. } //namespace boost{
  51. #include <boost/interprocess/detail/config_end.hpp>
  52. #endif //#ifndef BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED