summaryrefslogtreecommitdiff
path: root/goo/gmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'goo/gmem.h')
-rw-r--r--goo/gmem.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/goo/gmem.h b/goo/gmem.h
index 898f3393..4dad2d3a 100644
--- a/goo/gmem.h
+++ b/goo/gmem.h
@@ -25,6 +25,7 @@
#ifndef GMEM_H
#define GMEM_H
+#include <memory>
#include <stdio.h>
#include "poppler-config.h"
@@ -89,4 +90,37 @@ extern char *gstrndup(const char *s, size_t n);
}
#endif
+/* Remove this once we switch to C++14 */
+#if __cplusplus < 201400L
+namespace std {
+template<class T> struct _Unique_if {
+ typedef unique_ptr<T> _Single_object;
+};
+
+template<class T> struct _Unique_if<T[]> {
+ typedef unique_ptr<T[]> _Unknown_bound;
+};
+
+template<class T, size_t N> struct _Unique_if<T[N]> {
+ typedef void _Known_bound;
+};
+
+template<class T, class... Args> inline typename _Unique_if<T>::_Single_object
+make_unique(Args&&... args)
+{
+ return unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+template<class T> inline typename _Unique_if<T>::_Unknown_bound
+make_unique(size_t n)
+{
+ typedef typename remove_extent<T>::type U;
+ return unique_ptr<T>(new U[n]());
+}
+
+template<class T, class... Args> typename _Unique_if<T>::_Known_bound
+make_unique(Args&&...) = delete;
+}
+#endif
+
#endif