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 support for accessing the underlying pointer type via a dispatch #85

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented Apr 14, 2024

Since #79, proxy allows invocation of a dispatch to fallback to a default implementation without the context of the underlying entity. However, it is not enough for the scenarios where a concrete dispatch wants to observe the pointer without dereferencing it. One example is that when a proxy holds an instance of std::shared_ptr, there is currently no API to create an std::weak_ptr from it.

In this change, another fallback of dispatch invocation was introduced. Specifically, for a dispatch type D, one of its declared overload type O (R(Args...) noexcept(NE)), and a pointer type P, overload resolution will happen in the following sequence:

  • Instantiate and call the invoker with the dereference value from the pointer when std::is(_nothrow)_invocable_r_v<R, typename D::template invoker<target-type-of<P>>, target-type-of<P>&, Args...> is true, or otherwise
  • [NEW] Instantiate and call the invoker with the const reference of the pointer when std::is(_nothrow)_invocable_r_v<R, typename D::template invoker<const P>, const P&, Args...> is true, or otherwise
  • Instantiate the invoker with void and call the invoker without any context from the proxy object when std::is(_nothrow)_invocable_r_v<R, typename D::template invoker<void>, Args...> if true, or otherwise
  • The invocation is ill-formed.

This change is covered by a new unit test case ProxyInvocationTests.TestObserverDispatch.

Fixes #84

@mingxwa mingxwa requested review from lyf6lyf and tian-lt April 15, 2024 11:39
@mingxwa mingxwa assigned mingxwa and unassigned lyf6lyf, tian-lt and guominrui Apr 15, 2024
@mingxwa mingxwa merged commit c8f0b6b into microsoft:main Apr 16, 2024
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/ptr-dispatch branch April 16, 2024 01:03
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

Successfully merging this pull request may close these issues.

Missing API to interact with the underlying pointer types
4 participants