# HG changeset patch # User Teemu Piippo # Date 1521818086 -7200 # Node ID 8d22e1dd272d24b5f8c47ef97945c9f45779e042 # Parent e5c1320e1018828b2d91b83e25a8bc8f805e5dad ported qOverload to drop minimum Qt requirement down to 5.5 diff -r e5c1320e1018 -r 8d22e1dd272d CMakeLists.txt --- 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) diff -r e5c1320e1018 -r 8d22e1dd272d src/basics.h --- 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 +struct QNonConstOverload +{ + template + Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } + template + static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } +}; +template +struct QConstOverload +{ + template + Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } + template + static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } +}; +template +struct QOverload : QConstOverload, QNonConstOverload +{ + using QConstOverload::of; + using QConstOverload::operator(); + using QNonConstOverload::of; + using QNonConstOverload::operator(); + template + Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } + template + static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) + { return ptr; } +}; +template Q_CONSTEXPR Q_DECL_UNUSED QOverload qOverload = {}; +template Q_CONSTEXPR Q_DECL_UNUSED QConstOverload qConstOverload = {}; +template Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload qNonConstOverload = {}; +#endif + class Matrix; using GLRotationMatrix = QMatrix4x4; @@ -445,3 +485,14 @@ else flagset &= ~static_cast(Flag); } + +/* + * Returns a singleton of type T, useful for providing a valid but unused + * pointer. + */ +template +inline T& sink() +{ + static T result; + return result; +}