From b517f9cd2684d2b6a5540c9ff64bad19acee4bc1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 17 Oct 2018 13:28:05 +0300 Subject: Add function_cast() to utility.mxx --- libbutl/utility.ixx | 9 +++++++++ libbutl/utility.mxx | 6 ++++++ libbutl/uuid-linux.cxx | 13 ++----------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index 565a694..e17462a 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -212,4 +212,13 @@ namespace butl return nullopt; } + + template + inline F + function_cast (void* p) + { + union { void* p; F f; } r; + r.p = p; + return r.f; + } } diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 54c7b43..f944599 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -315,6 +315,12 @@ LIBBUTL_MODEXPORT namespace butl F f_; }; + // Cleanly cast dlsym() result (void*) to a function pointer. + // + template + F + function_cast (void*); + // Call a function if there is an exception. // diff --git a/libbutl/uuid-linux.cxx b/libbutl/uuid-linux.cxx index 7396910..cae8aae 100644 --- a/libbutl/uuid-linux.cxx +++ b/libbutl/uuid-linux.cxx @@ -14,6 +14,8 @@ #include // move() #include +#include // function_cast() + using namespace std; namespace butl @@ -48,17 +50,6 @@ namespace butl static void* libuuid; - // Use a union to cleanly cast dlsym() result (void*) to a function pointer. - // - template - static inline F - function_cast (void* p) - { - union { void* p; F f; } r; - r.p = p; - return r.f; - }; - static inline void dlfail (string what) { -- cgit v1.1