Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature macro to allow implicit cast of UniqueHandle to hpp handles #1731

Closed
raphaelthegreat opened this issue Nov 15, 2023 · 5 comments · Fixed by #1771
Closed

Add feature macro to allow implicit cast of UniqueHandle to hpp handles #1731

raphaelthegreat opened this issue Nov 15, 2023 · 5 comments · Fixed by #1771

Comments

@raphaelthegreat
Copy link

UniqueHandles are a great way of ensuring automatic resource destruction and cleaner code. However the constant need to run .get() or operator* to retrieve the underlying handle for CreateInfo structures or vulkan calls makes them more cumbersome to use than normal handles. I feel that trying to mimic the std::unique_ptr API here doesn't make much sense, considering that handles are most often used in such a manner compared to e.g running member functions with operator->. So I feel it would be useful to add new feature macro, for example VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST, that will define an implicit convertion operator to the underlying handle

@Pacheco95
Copy link

They could create a constructor like this at

# if !defined( VULKAN_HPP_NO_SMART_HANDLE )

// vulkan.hpp:837
template <typename Type, typename Dispatch>
class UniqueHandleTraits;

template <typename Type, typename Dispatch>
class UniqueHandle : public UniqueHandleTraits<Type, Dispatch>::deleter
{
 private:
  using Deleter = typename UniqueHandleTraits<Type, Dispatch>::deleter;

 public:
#if defined(VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST)
  UniqueHandle(Type t) : Deleter(), m_value(t) {}
#endif

  // ...

 private:
  Type m_value;
};

@Pacheco95
Copy link

If the maintainers agree I can make a PR

@raphaelthegreat
Copy link
Author

There is already such constructor. And this isn't the same as an implicit convertion operator anyway.

explicit UniqueHandle( Type const & value, Deleter const & deleter = Deleter() ) VULKAN_HPP_NOEXCEPT

@Pacheco95
Copy link

But this is an explicit constructor

@asuessenbach
Copy link
Contributor

Thanks for your request.
I think, this feature is worth to have, so (as stated in #1771), I added the implicit cast to the UniqueHandles and the SharedHandles, controlled by the opt-in define VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST.'
The vk::raii::Handles get the implicit cast unconditionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants