aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-17 13:28:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-17 13:28:05 +0300
commitb517f9cd2684d2b6a5540c9ff64bad19acee4bc1 (patch)
tree9d195ed3d7a28ed5dba470c08df1e98e62107d61
parent69f5ba17eef319bc112cadd54f18cccc10495ecb (diff)
Add function_cast() to utility.mxx
-rw-r--r--libbutl/utility.ixx9
-rw-r--r--libbutl/utility.mxx6
-rw-r--r--libbutl/uuid-linux.cxx13
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 <typename F>
+ 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 <typename F>
+ 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 <utility> // move()
#include <system_error>
+#include <libbutl/utility.mxx> // 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 <typename F>
- 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)
{