KhronosGroup / Vulkan-Hpp

Open-Source Vulkan C++ API
Apache License 2.0
3.06k stars 302 forks source link

Allow destructuring of ResultValue with std::tie #1882

Open HildarTheDorf opened 2 months ago

HildarTheDorf commented 2 months ago

Currently it is possible to do the following as ResultValue<T> provides a cast operator to std::tuple<vk:Result, T>: const auto [acquireResult, imageIndex] = _device->acquireNextImageKHR(...);.

I would like to be able to do this: std::tie(std::ignore, _imageIndex) = _device->acquireNextImageKHR(...);[^1] however it currently fails to compile.

As a work around I either have to static_cast the ResultValue to std::tuple, or write a helper function that does such. Would it be possible to alter vk::ResultValue to allow this implicitly?

[^1]: Note that the actual usefulness of ignoring the result of vkAcquireNextImageKHR is beyond the scope of this issue.

sharadhr commented 2 months ago

Ah, how nice it'd be if C++ had built-in ignores like Rust or C#; then we could just write auto const& [_, imageIndex] = ....

In the mean time, this sounds like a reasonable request, I'll work on it.

qbojj commented 1 month ago

@sharadhr This is already in C++26 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2169r4.pdf

BohdanCodes commented 2 weeks ago

std::tie(result, backBufferIndex) = swapchainData.swapchain.acquireNextImage(...) is an actual snippet from my C++20 sample... std::ignore works in place of result as well. I'm using Vulkan SDK 1.3.280.0.