summaryrefslogtreecommitdiff
path: root/glib/glibmm/utility.h
diff options
context:
space:
mode:
Diffstat (limited to 'glib/glibmm/utility.h')
-rw-r--r--glib/glibmm/utility.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/glib/glibmm/utility.h b/glib/glibmm/utility.h
index eaf4c15a..39c74a9f 100644
--- a/glib/glibmm/utility.h
+++ b/glib/glibmm/utility.h
@@ -158,6 +158,25 @@ destroy_notify_delete(void* data)
delete static_cast<T*>(data);
}
+// Conversion between different types of function pointers with
+// reinterpret_cast can make gcc8 print a warning.
+// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
+/** Returns the supplied bit pattern, interpreted as another type.
+ *
+ * When reinterpret_cast causes a compiler warning or error, this function
+ * may work. Intended mainly for conversion between different types of pointers.
+ */
+template <typename T_out, typename T_in>
+inline T_out bitwise_equivalent_cast(T_in in)
+{
+ union {
+ T_in in;
+ T_out out;
+ } u;
+ u.in = in;
+ return u.out;
+}
+
} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */