From d2472e229c9742998452c7187c1e07220a383b21 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 7 Sep 2017 12:48:47 +1000 Subject: [PATCH] except: allow void functions in try_func --- except.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/except.hpp b/except.hpp index f8c4c48..3b8769e 100644 --- a/except.hpp +++ b/except.hpp @@ -36,20 +36,31 @@ namespace cruft::vk { /// invokes a supplied function with the given arguments and tests - /// that it returns indicating success using try_code. + /// that it indicates success using try_code iff it returns a VkResult, + /// else it returns the result of the function. + /// + /// while it would simplify writing this function to avoid + /// non-VkResult functions it simplifies some of the upper layers of + /// try_foo functions to allow them anyway (eg, + /// vkGetBufferMemoryRequirements is otherwise usable with try_query + /// if we ignore the VkResult requirement) template < typename FuncT, typename ...Args > - static void + static auto try_func (FuncT &&func, Args &&...args) { - static_assert(std::is_same_v< - typename func_traits::return_type, - VkResult - >); - - try_code (func (std::forward (args)...)); + if constexpr (std::is_same_v< + typename func_traits::return_type, + VkResult + >) + { + try_code (func (std::forward (args)...)); + return; + } + else + return func (std::forward (args)...); }