make_shared_array.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2012-2017 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
  8. #define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
  9. #include <boost/smart_ptr/allocate_shared_array.hpp>
  10. namespace boost {
  11. template<class T>
  12. inline typename detail::sp_if_size_array<T>::type
  13. make_shared()
  14. {
  15. return boost::allocate_shared<T>(std::allocator<typename
  16. detail::sp_array_scalar<T>::type>());
  17. }
  18. template<class T>
  19. inline typename detail::sp_if_size_array<T>::type
  20. make_shared(const typename detail::sp_array_element<T>::type& value)
  21. {
  22. return boost::allocate_shared<T>(std::allocator<typename
  23. detail::sp_array_scalar<T>::type>(), value);
  24. }
  25. template<class T>
  26. inline typename detail::sp_if_array<T>::type
  27. make_shared(std::size_t size)
  28. {
  29. return boost::allocate_shared<T>(std::allocator<typename
  30. detail::sp_array_scalar<T>::type>(), size);
  31. }
  32. template<class T>
  33. inline typename detail::sp_if_array<T>::type
  34. make_shared(std::size_t size,
  35. const typename detail::sp_array_element<T>::type& value)
  36. {
  37. return boost::allocate_shared<T>(std::allocator<typename
  38. detail::sp_array_scalar<T>::type>(), size, value);
  39. }
  40. template<class T>
  41. inline typename detail::sp_if_size_array<T>::type
  42. make_shared_noinit()
  43. {
  44. return allocate_shared_noinit<T>(std::allocator<typename
  45. detail::sp_array_scalar<T>::type>());
  46. }
  47. template<class T>
  48. inline typename detail::sp_if_array<T>::type
  49. make_shared_noinit(std::size_t size)
  50. {
  51. return allocate_shared_noinit<T>(std::allocator<typename
  52. detail::sp_array_scalar<T>::type>(), size);
  53. }
  54. } /* boost */
  55. #endif