From 78204f6ce7e8bc942ad036287cfc28a6a77dfee0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 Jan 2019 16:02:32 +0000 Subject: Tidy getHelper with constexpr and lambda --- netfs/fuse/fuseAppBase.h | 53 ++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h index d899e00..5cc8f7f 100644 --- a/netfs/fuse/fuseAppBase.h +++ b/netfs/fuse/fuseAppBase.h @@ -138,39 +138,34 @@ class DLL_PUBLIC FuseAppBase { static void fuseDestroy(void *); template - static typename std::enable_if::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...)) + static int(*getHelper(int(FuseAppBase::*)(Args...)))(Args...) { - return &helper; - } - template - static typename std::enable_if::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...)) - { - return nullptr; - } - template - static int helper(Args ... a) - { - for (int t = 0; ; ++t) { - try { - fuseApp->beforeOperation(); - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (t < 10) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; + if constexpr (!std::is_same::value) { + return [](Args ... a) { + for (int t = 0; ; ++t) { + try { + fuseApp->beforeOperation(); + return (fuseApp->*bfunc)(a...); + } + catch (const std::exception & ex) { + if (t < 10) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + } + else { + fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(bfunc).name()); + return -EIO; + } + } + catch (...) { + fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name()); + return -EIO; } } - else { - fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(f).name()); - return -EIO; - } - } - catch (...) { - fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name()); - return -EIO; - } + }; } + return nullptr; } template static int internalHelper(Args ... a) -- cgit v1.2.3