summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-01-05 16:02:32 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2019-01-05 16:18:05 +0000
commit78204f6ce7e8bc942ad036287cfc28a6a77dfee0 (patch)
treef64e824eac18403a4b823f83ad681aa16b7305b3
parentIce 3.7 (diff)
downloadnetfs-78204f6ce7e8bc942ad036287cfc28a6a77dfee0.tar.bz2
netfs-78204f6ce7e8bc942ad036287cfc28a6a77dfee0.tar.xz
netfs-78204f6ce7e8bc942ad036287cfc28a6a77dfee0.zip
Tidy getHelper with constexpr and lambda
-rw-r--r--netfs/fuse/fuseAppBase.h53
1 files 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 <typename BFunc, typename IFunc, BFunc bfunc, typename ... Args>
- static typename std::enable_if<!std::is_same<BFunc, IFunc>::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...))
+ static int(*getHelper(int(FuseAppBase::*)(Args...)))(Args...)
{
- return &helper<BFunc, bfunc, Args...>;
- }
- template <typename BFunc, typename IFunc, BFunc bfunc, typename ... Args>
- static typename std::enable_if<std::is_same<BFunc, IFunc>::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...))
- {
- return nullptr;
- }
- template <typename Func, Func f, typename ... Args>
- 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<BFunc, IFunc>::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 <typename Func, Func f, typename ... Args>
static int internalHelper(Args ... a)