make_local_shared_array.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright 2017 Peter Dimov
  3. Copyright 2017-2019 Glen Joseph Fernandes
  4. (glenjofe@gmail.com)
  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/core/default_allocator.hpp>
  11. #include <boost/smart_ptr/allocate_local_shared_array.hpp>
  12. #include <boost/smart_ptr/detail/sp_type_traits.hpp>
  13. #include <type_traits>
  14. namespace boost {
  15. template<class T>
  16. inline typename std::enable_if<detail::sp_is_bounded_array<T>::value,
  17. local_shared_ptr<T> >::type
  18. make_local_shared()
  19. {
  20. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  21. detail::sp_array_element<T>::type>());
  22. }
  23. template<class T>
  24. inline typename std::enable_if<detail::sp_is_bounded_array<T>::value,
  25. local_shared_ptr<T> >::type
  26. make_local_shared(const typename std::remove_extent<T>::type& value)
  27. {
  28. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  29. detail::sp_array_element<T>::type>(), value);
  30. }
  31. template<class T>
  32. inline typename std::enable_if<detail::sp_is_unbounded_array<T>::value,
  33. local_shared_ptr<T> >::type
  34. make_local_shared(std::size_t size)
  35. {
  36. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  37. detail::sp_array_element<T>::type>(), size);
  38. }
  39. template<class T>
  40. inline typename std::enable_if<detail::sp_is_unbounded_array<T>::value,
  41. local_shared_ptr<T> >::type
  42. make_local_shared(std::size_t size,
  43. const typename std::remove_extent<T>::type& value)
  44. {
  45. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  46. detail::sp_array_element<T>::type>(), size, value);
  47. }
  48. template<class T>
  49. inline typename std::enable_if<detail::sp_is_bounded_array<T>::value,
  50. local_shared_ptr<T> >::type
  51. make_local_shared_noinit()
  52. {
  53. return boost::allocate_local_shared_noinit<T>(boost::
  54. default_allocator<typename detail::sp_array_element<T>::type>());
  55. }
  56. template<class T>
  57. inline typename std::enable_if<detail::sp_is_unbounded_array<T>::value,
  58. local_shared_ptr<T> >::type
  59. make_local_shared_noinit(std::size_t size)
  60. {
  61. return boost::allocate_local_shared_noinit<T>(boost::
  62. default_allocator<typename detail::sp_array_element<T>::type>(), size);
  63. }
  64. } /* boost */
  65. #endif