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

com_ptr::addressof method? #1423

Closed
tom-huntington opened this issue Jul 8, 2024 · 4 comments
Closed

com_ptr::addressof method? #1423

tom-huntington opened this issue Jul 8, 2024 · 4 comments

Comments

@tom-huntington
Copy link

tom-huntington commented Jul 8, 2024

Most D3D APIs take a T *const *ppT parameter (i.e. an array of pointers). With WRL::ComPtr you could use GetAddressOf to get the argument to parse. C++/WinRT's com_ptr::put releases its reference before passing you a pointer to what it owns.

Which is safe, but this means you have to do the following dance when parsing only one pointer

auto pSrv = m_srv.get();
context.VSSetShaderResources(0, 1, &pSrv);

which is unnecessarily verbose, as you could provide

template <typename T>
struct com_ptr
{
    type* const* put_const() const noexcept
    {
        WINRT_ASSERT(m_ptr);
        return &m_ptr;
    }
}
context.VSSetShaderResources(0, 1, m_srv.put_const());
@sylveon
Copy link
Contributor

sylveon commented Jul 8, 2024

I would argue against this because:

  • put const doesn't make it obvious to the reader what is happening here. The code is not actually putting anything.
  • it is inconsistent that all put methods releases the pointer, but this one doesn't

I'm not opposed to the idea, but it would need a different name.

@tom-huntington
Copy link
Author

tom-huntington commented Jul 8, 2024

Since every variable is a length one array maybe as_const_c_array. This might be a bit inconsistent with the existing as/try_as methods. view_as_const, const_view?

Feel free to close if this is more bikeshedding than it is worth.

1-1 functionality with WRL::ComPtr would be nice though.

@sylveon
Copy link
Contributor

sylveon commented Jul 8, 2024

Something like addressof() would work better - and it's also the name used by wil. Have you considered using wil for your com_ptr?

Also I will point out that WRL::ComPtr's operator& does release the held object as well, according to docs.

@kennykerr
Copy link
Collaborator

I believe the WIL version has a lot more bells and whistles.

@tom-huntington tom-huntington changed the title com_ptr::put_const method? com_ptr::addressof method? Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants