4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Guillaume Munch
9 * Full author contact details are available in file CREDITS.
12 #ifndef LYX_UNIQUE_PTR_H
13 #define LYX_UNIQUE_PTR_H
17 namespace lyx { using std::unique_ptr; }
20 /// Define lyx::make_unique() across platforms
22 #ifdef HAVE_DEF_MAKE_UNIQUE
24 namespace lyx { using std::make_unique; }
27 // For all other compilers:
28 // using https://isocpp.org/files/papers/N3656.txt
31 #include <type_traits>
39 template<class T> struct _Unique_if {
40 typedef unique_ptr<T> _Single_object;
43 template<class T> struct _Unique_if<T[]> {
44 typedef unique_ptr<T[]> _Unknown_bound;
47 template<class T, size_t N> struct _Unique_if<T[N]> {
48 typedef void _Known_bound;
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)...));
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]());
66 template<class T, class... Args>
67 typename _Unique_if<T>::_Known_bound
68 make_unique(Args&&...) = delete;
72 #endif // definition of make_unique
74 #endif // LYX_UNIQUE_PTR_H