Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 1 | //===-- Utils.h -------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Jonas Devlieghere | cdc514e | 2020-02-17 15:57:45 -0800 | [diff] [blame] | 9 | #ifndef LLDB_SOURCE_API_UTILS_H |
| 10 | #define LLDB_SOURCE_API_UTILS_H |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/ADT/STLExtras.h" |
| 13 | #include <memory> |
| 14 | |
| 15 | namespace lldb_private { |
| 16 | |
| 17 | template <typename T> std::unique_ptr<T> clone(const std::unique_ptr<T> &src) { |
| 18 | if (src) |
Jonas Devlieghere | a8f3ae7 | 2019-08-14 22:19:23 +0000 | [diff] [blame] | 19 | return std::make_unique<T>(*src); |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 20 | return nullptr; |
| 21 | } |
| 22 | |
| 23 | template <typename T> std::shared_ptr<T> clone(const std::shared_ptr<T> &src) { |
| 24 | if (src) |
| 25 | return std::make_shared<T>(*src); |
| 26 | return nullptr; |
| 27 | } |
| 28 | |
| 29 | } // namespace lldb_private |
| 30 | #endif |