GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
MakeUnique.h
1 /*
2  * GDevelop Core
3  * This project is released under the MIT License.
4  *
5  * This file is from https://isocpp.org/files/papers/N3656.txt
6  */
7 #ifndef GDCORE_MAKEUNIQUE_H
8 #define GDCORE_MAKEUNIQUE_H
9 
10 #include <memory>
11 
15 namespace gd {
16 
17 template <class T>
18 struct _Unique_if {
19  typedef std::unique_ptr<T> _Single_object;
20 };
21 
22 template <class T>
23 struct _Unique_if<T[]> {
24  typedef std::unique_ptr<T[]> _Unknown_bound;
25 };
26 
27 template <class T, size_t N>
28 struct _Unique_if<T[N]> {
29  typedef void _Known_bound;
30 };
31 
32 template <class T, class... Args>
33 typename _Unique_if<T>::_Single_object make_unique(Args&&... args) {
34  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
35 }
36 
37 template <class T>
38 typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
39  typedef typename std::remove_extent<T>::type U;
40  return std::unique_ptr<T>(new U[n]());
41 }
42 
43 template <class T, class... Args>
44 typename _Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
45 
46 } // namespace gd
47 
48 #endif
Definition: CommonTools.h:24
Definition: MakeUnique.h:18