]> git.lyx.org Git - lyx.git/blob - src/support/unique_ptr.h
Remove updateInfo() calls in favor of doing the relevant work
[lyx.git] / src / support / unique_ptr.h
1 // -*- C++ -*-
2 /**
3  * \file unique_ptr.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Guillaume Munch
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_UNIQUE_PTR_H
13 #define LYX_UNIQUE_PTR_H
14
15 #include <memory>
16
17 namespace lyx { using std::unique_ptr; }
18
19
20 /// Define lyx::make_unique() across platforms
21
22 #ifdef HAVE_DEF_MAKE_UNIQUE
23
24 namespace lyx { using std::make_unique; }
25
26 #else
27 // For all other compilers:
28 // using https://isocpp.org/files/papers/N3656.txt
29
30 #include <cstddef>
31 #include <type_traits>
32 #include <utility>
33
34
35 namespace lyx {
36
37 namespace {
38
39 template<class T> struct _Unique_if {
40         typedef unique_ptr<T> _Single_object;
41 };
42
43 template<class T> struct _Unique_if<T[]> {
44         typedef unique_ptr<T[]> _Unknown_bound;
45 };
46
47 template<class T, size_t N> struct _Unique_if<T[N]> {
48         typedef void _Known_bound;
49 };
50
51 } // namespace
52
53 template<class T, class... Args>
54 typename _Unique_if<T>::_Single_object
55 make_unique(Args&&... args) {
56         return unique_ptr<T>(new T(std::forward<Args>(args)...));
57 }
58
59 template<class T>
60 typename _Unique_if<T>::_Unknown_bound
61 make_unique(size_t n) {
62         typedef typename std::remove_extent<T>::type U;
63         return unique_ptr<T>(new U[n]());
64 }
65
66 template<class T, class... Args>
67 typename _Unique_if<T>::_Known_bound
68 make_unique(Args&&...) = delete;
69
70 } // namespace lyx
71
72 #endif // definition of make_unique
73
74 #endif // LYX_UNIQUE_PTR_H