except: add try_array

This commit is contained in:
Danny Robson 2017-09-06 13:41:01 +10:00
parent 83e7621b40
commit 9a07fc2496

View File

@ -12,7 +12,7 @@
* limitations under the License.
*
* Copyright:
* 2016, Danny Robson <danny@nerdcruft.net>
* 2016-2017, Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_VK_EXCEPT_HPP
@ -20,6 +20,9 @@
#include "./vk.hpp"
#include <cruft/util/debug.hpp>
#include <cruft/util/types/traits.hpp>
#include <exception>
#include <functional>
#include <type_traits>
@ -42,7 +45,7 @@ namespace cruft::vk {
try_func (FuncT &&func, Args &&...args)
{
static_assert(std::is_same_v<
std::result_of_t<FuncT(Args...)>,
typename func_traits<FuncT>::return_type,
VkResult
>);
@ -61,6 +64,32 @@ namespace cruft::vk {
try_func (func, std::forward<Args> (args)..., &value);
return value;
}
template <
template <typename...> 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<FuncT>::argument_types
>
>;
ContainerT<ResultT> values (expected);
uint32_t found = 0;
try_func (func, args..., &found, std::data (values));
CHECK_EQ (expected, found);
return values;
}
};