You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
845 B

  1. #include <cstddef>
  2. #include <memory>
  3. #include <type_traits>
  4. #include <utility>
  5. namespace std
  6. {
  7. template<class T> struct _Unique_if
  8. {
  9. typedef unique_ptr<T> _Single_object;
  10. };
  11. template<class T> struct _Unique_if<T[]>
  12. {
  13. typedef unique_ptr<T[]> _Unknown_bound;
  14. };
  15. template<class T, size_t N> struct _Unique_if<T[N]>
  16. {
  17. typedef void _Known_bound;
  18. };
  19. template<class T, class... Args>
  20. typename _Unique_if<T>::_Single_object
  21. make_unique(Args&&... args)
  22. {
  23. return unique_ptr<T>(new T(std::forward<Args>(args)...));
  24. }
  25. template<class T>
  26. typename _Unique_if<T>::_Unknown_bound
  27. make_unique(size_t n)
  28. {
  29. typedef typename remove_extent<T>::type U;
  30. return unique_ptr<T>(new U[n]());
  31. }
  32. template<class T, class... Args>
  33. typename _Unique_if<T>::_Known_bound
  34. make_unique(Args&&...) = delete;
  35. }