Advertisement
Guest User

Untitled

a guest
Feb 7th, 2012
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. // Please Visual Studio, just give me variadic templates! :(
  2. template<typename T>
  3. std::unique_ptr<T> make_unique()
  4. {
  5.   return std::unique_ptr<T>(new T());
  6. }
  7. template<typename T, typename A1>
  8. std::unique_ptr<T> make_unique(A1&& arg1)
  9. {
  10.   return std::unique_ptr<T>(new T(std::forward<A1>(arg1)));
  11. }
  12. template<typename T, typename A1, typename A2>
  13. std::unique_ptr<T> make_unique(A1&& arg1, A2&& arg2)
  14. {
  15.   return std::unique_ptr<T>(new T(std::forward<A1>(arg1), std::forward<A2>(arg2)));
  16. }
  17. template<typename T, typename A1, typename A2, typename A3>
  18. std::unique_ptr<T> make_unique(A1&& arg1, A2&& arg2, A3&& arg3)
  19. {
  20.   return std::unique_ptr<T>(new T(std::forward<A1>(arg1),
  21.     std::forward<A2>(arg2), std::forward<A3>(arg3)));
  22. }
  23. template<typename T, typename A1, typename A2, typename A3, typename A4>
  24. std::unique_ptr<T> make_unique(A1&& arg1, A2&& arg2, A3&& arg3, A4&& arg4)
  25. {
  26.   return std::unique_ptr<T>(new T(std::forward<A1>(arg1), std::forward<A2>(arg2),
  27.     std::forward<A3>(arg3), std::forward<A4>(arg4)));
  28. }
  29. template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
  30. std::unique_ptr<T> make_unique(A1&& arg1, A2&& arg2, A3&& arg3, A4&& arg4, A5&& arg5)
  31. {
  32.   return std::unique_ptr<T>(new T(std::forward<A1>(arg1), std::forward<A2>(arg2),
  33.     std::forward<A3>(arg3), std::forward<A4>(arg4), std::forward<A5>(arg5)));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement