make_shared_array.hpp 1.9 KB

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