fork download
  1. #include <memory>
  2. #include <utility>
  3. #include <type_traits>
  4.  
  5. template <bool, typename T, std::size_t>
  6. struct maybe_array
  7. {
  8. typedef T type;
  9. };
  10.  
  11. template <typename T, std::size_t N>
  12. struct maybe_array<true, T, N>
  13. {
  14. typedef typename std::remove_extent<T>::type type[N];
  15. };
  16.  
  17. template <typename T, typename ...Args>
  18. std::unique_ptr<T> make_unique(Args &&... args)
  19. {
  20. return std::unique_ptr<T>(new typename maybe_array<std::is_array<T>::value, T, sizeof...(Args)>::type { std::forward<Args>(args)... });
  21. }
  22.  
  23. int main()
  24. {
  25. auto p = make_unique<int[]>(11, 22, 33);
  26. }
  27.  
Success #stdin #stdout 0s 3012KB
stdin
Standard input is empty
stdout
Standard output is empty