From d9af320fbdfdadd70815d4f14a9116829dfabdf0 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 2 Nov 2018 17:16:31 +0300 Subject: Generalize function_cast() to cast between incompatible function pointers --- libbutl/utility.ixx | 6 +++--- libbutl/utility.mxx | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libbutl') diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index e17462a..1aa116b 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -213,11 +213,11 @@ namespace butl return nullopt; } - template + template inline F - function_cast (void* p) + function_cast (P* p) { - union { void* p; F f; } r; + union { P* p; F f; } r; r.p = p; return r.f; } diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index f944599..5d093ad 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -315,11 +315,12 @@ LIBBUTL_MODEXPORT namespace butl F f_; }; - // Cleanly cast dlsym() result (void*) to a function pointer. + // Cleanly cast between incompatible function types or dlsym() result + // (void*) to a function pointer. // - template + template F - function_cast (void*); + function_cast (P*); // Call a function if there is an exception. // -- cgit v1.1