Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Implement pointer-to-member support#111

Merged
mingxwa merged 4 commits intomicrosoft:mainfrom
mingxwa:user/mingxwa/dispatch-ptr
Jun 6, 2024
Merged

Implement pointer-to-member support#111
mingxwa merged 4 commits intomicrosoft:mainfrom
mingxwa:user/mingxwa/dispatch-ptr

Conversation

@mingxwa
Copy link
Contributor

@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 guominrui and tian-lt June 6, 2024 02:37
@mingxwa mingxwa self-assigned this Jun 6, 2024
tian-lt
tian-lt previously approved these changes Jun 6, 2024
@mingxwa mingxwa merged commit e60902c into microsoft:main Jun 6, 2024
@mingxwa mingxwa deleted the user/mingxwa/dispatch-ptr branch June 6, 2024 06:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for operator->*

2 participants