Advertisement
zhangsongcui

make_unique

Jul 22nd, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #if (__cplusplus >= 201103L) || (defined _MSC_VER && _MSC_VER >= 1600)
  2. #include <memory>
  3. #include <functional>
  4. #   ifdef _MSC_VER
  5. template <typename Type>
  6. inline std::unique_ptr<Type> make_unique() {
  7.     return std::unique_ptr<Type>(new Type());
  8. }
  9.  
  10. template <typename Type, typename Arg1>
  11. inline std::unique_ptr<Type> make_unique(Arg1&& arg1) {
  12.     return std::unique_ptr<Type>(new Type(std::forward<Arg1>(arg1)));
  13. }
  14.  
  15. template <typename Type, typename Arg1, typename Arg2>
  16. inline std::unique_ptr<Type> make_unique(Arg1&& arg1, Arg2&& arg2) {
  17.     return std::unique_ptr<Type>(new Type(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2)));
  18. }
  19. #   else
  20. template <typename Type, typename... Args>
  21. inline std::unique_ptr<Type> make_unique(Args... args) {
  22.     return std::unique_ptr<Type>(new Type(std::forward<Args>(args)...));
  23. }
  24. #   endif
  25. #else
  26. #   error ISO C++ 2011 standard is not enabled
  27. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement