From 9a07fc2496b649b027c4c7bdaf47a4b138013940 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 6 Sep 2017 13:41:01 +1000 Subject: [PATCH] except: add try_array --- except.hpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/except.hpp b/except.hpp index a4c0367..d6b305e 100644 --- a/except.hpp +++ b/except.hpp @@ -12,7 +12,7 @@ * limitations under the License. * * Copyright: - * 2016, Danny Robson + * 2016-2017, Danny Robson */ #ifndef CRUFT_VK_EXCEPT_HPP @@ -20,6 +20,9 @@ #include "./vk.hpp" +#include +#include + #include #include #include @@ -42,7 +45,7 @@ namespace cruft::vk { try_func (FuncT &&func, Args &&...args) { static_assert(std::is_same_v< - std::result_of_t, + typename func_traits::return_type, VkResult >); @@ -61,6 +64,32 @@ namespace cruft::vk { try_func (func, std::forward (args)..., &value); return value; } + + + template < + template class ContainerT, + typename FuncT, + typename ...Args + > + static auto + try_array (FuncT &&func, Args &&...args) + { + uint32_t expected = 0; + try_func (func, args..., &expected, nullptr); + + using ResultT = std::remove_pointer_t< + std::tuple_element_t< + sizeof...(Args) + 1, + typename func_traits::argument_types + > + >; + + ContainerT values (expected); + uint32_t found = 0; + try_func (func, args..., &found, std::data (values)); + CHECK_EQ (expected, found); + return values; + } };