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

Feature: Support overloads in dispatch definition #45

Merged
merged 9 commits into from
Nov 25, 2023

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented Nov 23, 2023

Overloading is a widely used paradigm that helps reducing the effort of naming of abstraction. However, it is not supported in the existing implementation of proxy. This PR aims to add this capability inspired by #43. After this change, overloading with different signatures becomes available in a single dispatch. An operator() was also added to proxy to simplify the invocation syntax when only one dispatch is specified. Unit test cases are updated accordingly to cover this change. Documentations will be updated later.

BREAKING CHANGE: pro::dispatch no longer supports adaption with CPO. This feature has been moved to another class template pro::dispatch_adaptor. pro::dispatch<std::size_t(), std::ranges::size> was a valid type before this change but not anymore. The equivalent type has become pro::dispatch_adaptor<std::ranges::size, std::size_t()> with this change.

The syntax to define a dispatch with single overload is the same as before:

struct foo : pro::dispatch<int(int)> {
  auto operator()(const auto& self, int val) { return self.foo(val); }
};

The syntax to define a dispatch with multiple overloads is similar:

struct foo : pro::dispatch<int(int), double(double)> {
  auto operator()(const auto& self, auto val) { return self.foo(val); }
};

See the updated unit test cases for more details.

tian-lt
tian-lt previously approved these changes Nov 25, 2023
proxy.h Show resolved Hide resolved
proxy.h Outdated Show resolved Hide resolved
proxy.h Show resolved Hide resolved
proxy.h Outdated Show resolved Hide resolved
@mingxwa mingxwa merged commit d8dbbb0 into microsoft:main Nov 25, 2023
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/feature-overloads branch November 25, 2023 14:08
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.

2 participants