zstein | f42cc9d | 2017-03-27 16:17:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Karl Wiberg | 4c77dcd | 2018-06-29 14:34:50 +0200 | [diff] [blame] | 11 | // This file contains rtc::MakeUnique and rtc::WrapUnique, which are backwards |
| 12 | // compatibility aliases for absl::make_unique and absl::WrapUnique, |
| 13 | // respectively. This file will go away soon; use the Abseil types directly in |
| 14 | // new code. |
zstein | f42cc9d | 2017-03-27 16:17:19 -0700 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #ifndef RTC_BASE_PTR_UTIL_H_ |
| 17 | #define RTC_BASE_PTR_UTIL_H_ |
zstein | f42cc9d | 2017-03-27 16:17:19 -0700 | [diff] [blame] | 18 | |
Karl Wiberg | 4c77dcd | 2018-06-29 14:34:50 +0200 | [diff] [blame] | 19 | #include "absl/memory/memory.h" |
zstein | f42cc9d | 2017-03-27 16:17:19 -0700 | [diff] [blame] | 20 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 21 | namespace rtc { |
| 22 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 23 | template <typename T, typename... Args> |
Karl Wiberg | 4c77dcd | 2018-06-29 14:34:50 +0200 | [diff] [blame] | 24 | auto MakeUnique(Args&&... args) |
| 25 | -> decltype(absl::make_unique<T, Args...>(std::forward<Args>(args)...)) { |
| 26 | return absl::make_unique<T, Args...>(std::forward<Args>(args)...); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 29 | template <typename T> |
Karl Wiberg | 4c77dcd | 2018-06-29 14:34:50 +0200 | [diff] [blame] | 30 | auto MakeUnique(size_t n) -> decltype(absl::make_unique<T>(n)) { |
| 31 | return absl::make_unique<T>(n); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Karl Wiberg | 4c77dcd | 2018-06-29 14:34:50 +0200 | [diff] [blame] | 34 | using absl::WrapUnique; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 35 | |
| 36 | } // namespace rtc |
zstein | f42cc9d | 2017-03-27 16:17:19 -0700 | [diff] [blame] | 37 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 38 | #endif // RTC_BASE_PTR_UTIL_H_ |