Commit | Line | Data |
---|---|---|
fa5e9d57 PP |
1 | /* |
2 | * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
094bf3f2 SM |
7 | #ifndef BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP |
8 | #define BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP | |
fa5e9d57 PP |
9 | |
10 | #include <memory> | |
fa5e9d57 | 11 | #include <type_traits> |
c802cacb | 12 | #include <utility> |
fa5e9d57 | 13 | |
094bf3f2 | 14 | namespace bt2c { |
fa5e9d57 PP |
15 | |
16 | /* | |
17 | * Our implementation of std::make_unique<>() for C++11. | |
18 | */ | |
19 | template <typename T, typename... ArgTs> | |
20 | std::unique_ptr<T> makeUnique(ArgTs&&...args) | |
21 | { | |
22 | static_assert(!std::is_array<T>::value, "`T` is not an array (unsupported)."); | |
23 | ||
24 | return std::unique_ptr<T>(new T {std::forward<ArgTs>(args)...}); | |
25 | } | |
26 | ||
094bf3f2 | 27 | } /* namespace bt2c */ |
fa5e9d57 | 28 | |
094bf3f2 | 29 | #endif /* BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP */ |