ptr_util.h 677 B

1234567891011121314151617181920212223
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_MEMORY_PTR_UTIL_H_
  5. #define BASE_MEMORY_PTR_UTIL_H_
  6. #include <memory>
  7. #include <utility>
  8. namespace base {
  9. // Helper to transfer ownership of a raw pointer to a std::unique_ptr<T>.
  10. // Note that std::unique_ptr<T> has very different semantics from
  11. // std::unique_ptr<T[]>: do not use this helper for array allocations.
  12. template <typename T>
  13. std::unique_ptr<T> WrapUnique(T* ptr) {
  14. return std::unique_ptr<T>(ptr);
  15. }
  16. } // namespace base
  17. #endif // BASE_MEMORY_PTR_UTIL_H_