make_local_shared_array.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright 2017 Peter Dimov
  3. Copyright 2017-2019 Glen Joseph Fernandes
  4. ([email protected])
  5. Distributed under the Boost Software License, Version 1.0.
  6. (http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
  9. #define BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
  10. #include <boost/smart_ptr/detail/requires_cxx11.hpp>
  11. #include <boost/core/default_allocator.hpp>
  12. #include <boost/smart_ptr/allocate_local_shared_array.hpp>
  13. namespace boost {
  14. template<class T>
  15. inline typename enable_if_<is_bounded_array<T>::value,
  16. local_shared_ptr<T> >::type
  17. make_local_shared()
  18. {
  19. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  20. detail::sp_array_element<T>::type>());
  21. }
  22. template<class T>
  23. inline typename enable_if_<is_bounded_array<T>::value,
  24. local_shared_ptr<T> >::type
  25. make_local_shared(const typename remove_extent<T>::type& value)
  26. {
  27. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  28. detail::sp_array_element<T>::type>(), value);
  29. }
  30. template<class T>
  31. inline typename enable_if_<is_unbounded_array<T>::value,
  32. local_shared_ptr<T> >::type
  33. make_local_shared(std::size_t size)
  34. {
  35. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  36. detail::sp_array_element<T>::type>(), size);
  37. }
  38. template<class T>
  39. inline typename enable_if_<is_unbounded_array<T>::value,
  40. local_shared_ptr<T> >::type
  41. make_local_shared(std::size_t size,
  42. const typename remove_extent<T>::type& value)
  43. {
  44. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  45. detail::sp_array_element<T>::type>(), size, value);
  46. }
  47. template<class T>
  48. inline typename enable_if_<is_bounded_array<T>::value,
  49. local_shared_ptr<T> >::type
  50. make_local_shared_noinit()
  51. {
  52. return boost::allocate_local_shared_noinit<T>(boost::
  53. default_allocator<typename detail::sp_array_element<T>::type>());
  54. }
  55. template<class T>
  56. inline typename enable_if_<is_unbounded_array<T>::value,
  57. local_shared_ptr<T> >::type
  58. make_local_shared_noinit(std::size_t size)
  59. {
  60. return boost::allocate_local_shared_noinit<T>(boost::
  61. default_allocator<typename detail::sp_array_element<T>::type>(), size);
  62. }
  63. } /* boost */
  64. #endif