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.

make_unique.h 973B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <memory>
  3. #if __cplusplus <= 201103L
  4. namespace {
  5. template<class T>
  6. struct is_unbound_array : std::false_type {};
  7. template<class T>
  8. struct is_unbound_array<T[]> : std::true_type {};
  9. template<class T>
  10. struct is_bound_array : std::false_type {};
  11. template<class T, std::size_t N>
  12. struct is_bound_array<T[N]> : std::true_type {};
  13. }
  14. namespace std {
  15. template<typename T, typename... Args>
  16. typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type make_unique(Args&&... args) {
  17. return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
  18. }
  19. template<typename T>
  20. typename std::enable_if<is_unbound_array<T>::value, std::unique_ptr<T>>::type make_unique(size_t size) {
  21. return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
  22. }
  23. template< class T, class... Args >
  24. typename std::enable_if<is_bound_array<T>::value>::type make_unique( Args&&... args ) = delete;
  25. }
  26. #endif