ported qOverload to drop minimum Qt requirement down to 5.5

Fri, 23 Mar 2018 17:14:46 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 23 Mar 2018 17:14:46 +0200
changeset 1311
8d22e1dd272d
parent 1310
e5c1320e1018
child 1312
f2974f3ac1ab

ported qOverload to drop minimum Qt requirement down to 5.5

CMakeLists.txt file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Mar 23 17:13:35 2018 +0200
+++ b/CMakeLists.txt	Fri Mar 23 17:14:46 2018 +0200
@@ -15,6 +15,10 @@
 find_package (Qt5OpenGL REQUIRED)
 find_package (Qt5Network REQUIRED)
 
+if (Qt5Widgets_VERSION VERSION_LESS 5.5.0)
+	message(FATAL_ERROR "Qt5 version 5.5 required")
+endif()
+
 set (CMAKE_AUTOMOC ON)
 
 find_package (OpenGL REQUIRED)
--- a/src/basics.h	Fri Mar 23 17:13:35 2018 +0200
+++ b/src/basics.h	Fri Mar 23 17:14:46 2018 +0200
@@ -32,6 +32,46 @@
 #include "macros.h"
 #include "transform.h"
 
+#if (QT_VERSION < QT_VERSION_CHECK(5, 7, 0))
+template <typename... Args>
+struct QNonConstOverload
+{
+    template <typename R, typename T>
+    Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+    template <typename R, typename T>
+    static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+};
+template <typename... Args>
+struct QConstOverload
+{
+    template <typename R, typename T>
+    Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+    template <typename R, typename T>
+    static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+};
+template <typename... Args>
+struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
+{
+    using QConstOverload<Args...>::of;
+    using QConstOverload<Args...>::operator();
+    using QNonConstOverload<Args...>::of;
+    using QNonConstOverload<Args...>::operator();
+    template <typename R>
+    Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+    template <typename R>
+    static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
+    { return ptr; }
+};
+template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QOverload<Args...> qOverload = {};
+template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QConstOverload<Args...> qConstOverload = {};
+template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload<Args...> qNonConstOverload = {};
+#endif
+
 class Matrix;
 using GLRotationMatrix = QMatrix4x4;
 
@@ -445,3 +485,14 @@
 	else
 		flagset &= ~static_cast<T>(Flag);
 }
+
+/*
+ * Returns a singleton of type T, useful for providing a valid but unused
+ * pointer.
+ */
+template<typename T>
+inline T& sink()
+{
+	static T result;
+	return result;
+}

mercurial