• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef HISTREAMER_FOUNDATION_CPP_EXT_MEMORY_EXT_H
16 #define HISTREAMER_FOUNDATION_CPP_EXT_MEMORY_EXT_H
17 namespace OHOS {
18 namespace Media {
19 namespace CppExt {
20 template<class T> struct _unique_ptr_if {
21     typedef std::unique_ptr<T> _single_object;
22 };
23 
24 template<class T> struct _unique_ptr_if<T[]> {
25     typedef std::unique_ptr<T[]> _unknown_bound_array;
26 };
27 
28 template<class T, size_t N> struct _unique_ptr_if<T[N]> {
29     typedef void _known_bound_array; // not supported
30 };
31 
32 template<class T, class... U>
33 typename _unique_ptr_if<T>::_single_object make_unique(U&&... params)
34 {
35     return std::unique_ptr<T>(new T(std::forward<U>(params)...));
36 }
37 
38 template<class T>
39 typename _unique_ptr_if<T>::_unknown_bound_array make_unique(size_t n)
40 {
41     typedef typename std::remove_extent<T>::type U;
42     return std::unique_ptr<T>(new U[n]());
43 }
44 
45 template<class T, class... Args>
46 typename _unique_ptr_if<T>::_known_bound_array make_unique(Args&&...) = delete;
47 } // CppExt
48 } // Media
49 } // OHOS
50 #endif // HISTREAMER_FOUNDATION_CPP_EXT_MEMORY_EXT_H
51