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

Implement pointer-to-member support #111

Merged
merged 4 commits into from
Jun 6, 2024

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented Jun 6, 2024

Changes

  • Added pointer-to-member type dispatch_ptr and consteval function template get_dispatch_ptr() for proxy.
  • Added overloads of proxy::operator->*.
  • Added another unit test case for this change.

Here is a comparison table for the syntax of pointer-to-member in direct C++ types and proxy:

Semantics Direct C++ type T (value denotes a value of T) proxy type P (value denotes a value of P)
Pointer-to-member type (function) R (T::*)(Args...) P::dispatch_ptr<R(Args...)>
Pointer-to-member type (field) M T::* N/A
Acquire pointer-to-member (function template) &T::member<Args...> P::get_dispatch_ptr<Args...>
Invoke member function with pointer-to-member ptr (value.*ptr)(args...) (p->*ptr)(args...)

Note that we cannot use pointer-to-member in multiple inheritance today in MSVC due to a bug in the compiler implementation. Therefore, we fallback the implementation for MSVC to C-style offsetof. Interestingly, offsetof won't compile in GCC or clang in our scenario (probably we hit some limitations in macro expansion), but we have not investigated further while pointer-to-member works as expected in the two compilers.

Resolves #107

@mingxwa mingxwa requested review from tian-lt and guominrui June 6, 2024 02:37
@mingxwa mingxwa self-assigned this Jun 6, 2024
proxy.h Outdated Show resolved Hide resolved
tian-lt
tian-lt previously approved these changes Jun 6, 2024
@mingxwa mingxwa merged commit e60902c into microsoft:main Jun 6, 2024
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/dispatch-ptr branch June 6, 2024 06:22
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.

Add support for operator->*
2 participants