SkMakeUnique.h 618 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkMakeUnique_DEFINED
  8. #define SkMakeUnique_DEFINED
  9. #include <memory>
  10. namespace skstd {
  11. // std::make_unique is in C++14
  12. template<typename T, typename... Args>
  13. std::unique_ptr<T> make_unique(Args&&... args) {
  14. return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
  15. }
  16. template<typename T>
  17. std::unique_ptr<T> make_unique_default(size_t n) {
  18. return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]);
  19. }
  20. }
  21. #endif // SkMakeUnique_DEFINED