fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. template<class T, class... Types>
  5. inline auto make_unique(Types&&... Args) -> typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
  6. {
  7. return (std::unique_ptr<T>(new T(std::forward<Types>(Args)...)));
  8. }
  9.  
  10. template<class T>
  11. inline auto make_unique(size_t Size) -> typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0, std::unique_ptr<T>>::type
  12. {
  13. return (std::unique_ptr<T>(new typename std::remove_extent<T>::type[Size]()));
  14. }
  15.  
  16. int main()
  17. {
  18. auto test1 = make_unique<int[]>(10); // create an array of 10 ints
  19. auto test2 = make_unique<int>(10); // create a single int with a value of 10
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty