make_shared_array.hpp 2.1 KB

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