make_local_shared_array.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. namespace boost {
  13. template<class T>
  14. inline typename enable_if_<is_bounded_array<T>::value,
  15. local_shared_ptr<T> >::type
  16. make_local_shared()
  17. {
  18. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  19. detail::sp_array_element<T>::type>());
  20. }
  21. template<class T>
  22. inline typename enable_if_<is_bounded_array<T>::value,
  23. local_shared_ptr<T> >::type
  24. make_local_shared(const typename remove_extent<T>::type& value)
  25. {
  26. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  27. detail::sp_array_element<T>::type>(), value);
  28. }
  29. template<class T>
  30. inline typename enable_if_<is_unbounded_array<T>::value,
  31. local_shared_ptr<T> >::type
  32. make_local_shared(std::size_t size)
  33. {
  34. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  35. detail::sp_array_element<T>::type>(), size);
  36. }
  37. template<class T>
  38. inline typename enable_if_<is_unbounded_array<T>::value,
  39. local_shared_ptr<T> >::type
  40. make_local_shared(std::size_t size,
  41. const typename remove_extent<T>::type& value)
  42. {
  43. return boost::allocate_local_shared<T>(boost::default_allocator<typename
  44. detail::sp_array_element<T>::type>(), size, value);
  45. }
  46. template<class T>
  47. inline typename enable_if_<is_bounded_array<T>::value,
  48. local_shared_ptr<T> >::type
  49. make_local_shared_noinit()
  50. {
  51. return boost::allocate_local_shared_noinit<T>(boost::
  52. default_allocator<typename detail::sp_array_element<T>::type>());
  53. }
  54. template<class T>
  55. inline typename enable_if_<is_unbounded_array<T>::value,
  56. local_shared_ptr<T> >::type
  57. make_local_shared_noinit(std::size_t size)
  58. {
  59. return boost::allocate_local_shared_noinit<T>(boost::
  60. default_allocator<typename detail::sp_array_element<T>::type>(), size);
  61. }
  62. } /* boost */
  63. #endif