aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/Compat.h
diff options
context:
space:
mode:
authormitchell <unknown>2020-01-05 21:22:02 -0500
committermitchell <unknown>2020-01-05 21:22:02 -0500
commit60e87889d6438e386acf58c3967fb874af9aae82 (patch)
tree9c5c2660c59aff04ddedea19fa03fd271f8bba5c /include/Compat.h
parentdbb7374c185718655dd77c294eb281e8b93c538e (diff)
downloadscintilla-mirror-60e87889d6438e386acf58c3967fb874af9aae82.tar.gz
Added Sci::make_unique() and Sci::size() for better compatibility with the default branch.
std::make_unique() is c++14 and std::size() is c++17.
Diffstat (limited to 'include/Compat.h')
-rw-r--r--include/Compat.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/include/Compat.h b/include/Compat.h
new file mode 100644
index 000000000..712ff1373
--- /dev/null
+++ b/include/Compat.h
@@ -0,0 +1,51 @@
+// c++11 compatibility with some c++14 features and higher.
+// This helps minimize changes from the default branch.
+
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#ifdef __cplusplus
+
+#include <cstddef>
+#include <memory>
+#include <type_traits>
+#include <utility>
+
+namespace Sci {
+
+// std::make_unique
+template<class T> struct _Unique_if {
+ typedef std::unique_ptr<T> _Single_object;
+};
+template<class T> struct _Unique_if<T[]> {
+ typedef std::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>
+ typename _Unique_if<T>::_Single_object
+ make_unique(Args&&... args) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+ }
+template<class T>
+ typename _Unique_if<T>::_Unknown_bound
+ make_unique(size_t n) {
+ typedef typename std::remove_extent<T>::type U;
+ return std::unique_ptr<T>(new U[n]());
+ }
+template<class T, class... Args>
+ typename _Unique_if<T>::_Known_bound
+ make_unique(Args&&...) = delete;
+
+// std::size
+template <typename T, size_t N>
+constexpr size_t size(const T (&)[N]) noexcept {
+ return N;
+}
+
+}
+
+#endif
+
+#endif \ No newline at end of file