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 macros to simplify syntax of creating dispatches and facades #46

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented Nov 29, 2023

Changes

  • Added macros DEFINE_MEMBER_DISPATCH, DEFINE_FREE_DISPATCH, DEFINE_FACADE, and DEFINE_COPYABLE_FACADE. These macros are not intended to be included in the proposal of standardization, but should make the library easier to use before the static reflection standards are stabilized.
  • Removed class template pro::dispatch_adapter since it is shadowed by the macros.
  • Fixed a bug: When the required return type of an overload is void, but the concrete return type of a dispatch is not void, the code won't compile.
  • Updated unit tests and sample code accordingly.

Quick glance

Before:

struct Draw : pro::dispatch<void(std::ostream&)> {
  void operator()(const auto& self, std::ostream& out) { self.Draw(out); }
};
struct Area : pro::dispatch<double()> {
  double operator()(const auto& self) { return self.Area(); }
};
struct DrawableFacade : pro::facade<Draw, Area> {};

After:

DEFINE_MEMBER_DISPATCH(Draw, Draw, void(std::ostream&));
DEFINE_MEMBER_DISPATCH(Area, Area, double());
DEFINE_FACADE(DrawableFacade, Draw, Area);

@mingxwa mingxwa requested a review from tian-lt November 29, 2023 10:53
proxy.h Show resolved Hide resolved
tian-lt
tian-lt previously approved these changes Nov 29, 2023
@suy
Copy link

suy commented Nov 29, 2023

One nitpick: in places like DEFINE_MEMBER_DISPATCH(Area, Area, double()); it is not very clear what each "Area" is. One is the name of the struct, the other the member function called, but which is which? This is more obvious in the DEFINE_FREE_DISPATCH(ToString, to_string, std::string()); example. Naming is hard. :-)

@mingxwa
Copy link
Collaborator Author

mingxwa commented Nov 29, 2023

One nitpick: in places like DEFINE_MEMBER_DISPATCH(Area, Area, double()); it is not very clear what each "Area" is. One is the name of the struct, the other the member function called, but which is which? This is more obvious in the DEFINE_FREE_DISPATCH(ToString, to_string, std::string()); example. Naming is hard. :-)

That is true. I tried to refactor everything required by proxy into a namespace poly in the sample code to let people aware each macro defines a name. Does it look better now?

@suy
Copy link

suy commented Nov 29, 2023

It helps, thank you!

@mingxwa mingxwa merged commit 1937e4b into microsoft:main Nov 30, 2023
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/macro-v1 branch April 1, 2024 02:11
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.

None yet

3 participants