aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-11-02 17:16:31 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-11-02 17:16:31 +0300
commitd9af320fbdfdadd70815d4f14a9116829dfabdf0 (patch)
tree38e407df0aa9f728eaaa4437d7baa87a8a9447ee
parent1bd2a072d44893b78eac97ee81edd24023918e06 (diff)
Generalize function_cast() to cast between incompatible function pointers
-rw-r--r--libbutl/utility.ixx6
-rw-r--r--libbutl/utility.mxx7
2 files changed, 7 insertions, 6 deletions
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 <typename F>
+ template <typename F, typename P>
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 <typename F>
+ template <typename F, typename P>
F
- function_cast (void*);
+ function_cast (P*);
// Call a function if there is an exception.
//