KhronosGroup / Vulkan-Hpp

Open-Source Vulkan C++ API
Apache License 2.0
3.08k stars 304 forks source link

Move semantics for non-raii handles #1919

Closed siukosev closed 1 month ago

siukosev commented 2 months ago

For example: I'm using vk::Buffer in the standard layout structure(it shouldn't have any constructors, including move-constructor) so I can actively use designated initializers. Something like this:

struct VertexBuffer {
  vk::Buffer buffer;

  ~VertexBuffer() { vkDestroyBuffer(...); }
}

Of course vkDestroyBuffer is getting called during emplace_back(std::move(vbuff)) with valid buffer handle. Wouldn't it be more intuitive to implement move semantics for handles with something like this?

Buffer(Buffer&& rhs) {
  : m_buffer(exchange(rhs.m_buffer, {}))
{
}

Would you accept a PR with these changes?

asuessenbach commented 2 months ago

Yes, that seems to be reasonable. Would be great if you could provide a PR with these changes.