make_shared_array.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2012-2019 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/detail/requires_cxx11.hpp>
  10. #include <boost/core/default_allocator.hpp>
  11. #include <boost/smart_ptr/allocate_shared_array.hpp>
  12. namespace boost {
  13. template<class T>
  14. inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
  15. make_shared()
  16. {
  17. return boost::allocate_shared<T>(boost::default_allocator<typename
  18. detail::sp_array_element<T>::type>());
  19. }
  20. template<class T>
  21. inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
  22. make_shared(const typename remove_extent<T>::type& value)
  23. {
  24. return boost::allocate_shared<T>(boost::default_allocator<typename
  25. detail::sp_array_element<T>::type>(), value);
  26. }
  27. template<class T>
  28. inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
  29. make_shared(std::size_t size)
  30. {
  31. return boost::allocate_shared<T>(boost::default_allocator<typename
  32. detail::sp_array_element<T>::type>(), size);
  33. }
  34. template<class T>
  35. inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
  36. make_shared(std::size_t size, const typename remove_extent<T>::type& value)
  37. {
  38. return boost::allocate_shared<T>(boost::default_allocator<typename
  39. detail::sp_array_element<T>::type>(), size, value);
  40. }
  41. template<class T>
  42. inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
  43. make_shared_noinit()
  44. {
  45. return boost::allocate_shared_noinit<T>(boost::default_allocator<typename
  46. detail::sp_array_element<T>::type>());
  47. }
  48. template<class T>
  49. inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
  50. make_shared_noinit(std::size_t size)
  51. {
  52. return boost::allocate_shared_noinit<T>(boost::default_allocator<typename
  53. detail::sp_array_element<T>::type>(), size);
  54. }
  55. } /* boost */
  56. #endif