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

Improve invocation APIs and facilities to define an operator dispatch #106

Merged
merged 6 commits into from
Jun 4, 2024

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented May 31, 2024

Changes

  • Moved pro::proxy::invoke() out of the scope of class template proxy as a free function template pro::proxy_invoke().
  • Moved pro::proxy::reflect() out of the scope of class template proxy as a free function template pro::proxy_reflect().
  • Removed function template pro::lazy_eval() since it is no longer needed.
  • Moved type alias template pro::lazy_eval_t into namespace pro::details since it is not required with the "deducing this" feature in C++23 (it is discouraged for custom implementations of a dispatch to use something like lazy_eval_t when the language feature is implemented by a compiler).
  • Implemented the following macros:
#define PRO_DEF_OPERATOR_DISPATCH(__NAME, __SIGN) // see the implementation in proxy.h
#define PRO_DEF_OPERATOR_DISPATCH_WITH_DEFAULT(__NAME, __SIGN, __DEFFUNC) // see the implementation in proxy.h

#define PRO_DEF_PRE_OPERATOR_DISPATCH(__NAME, __SIGN) // see the implementation in proxy.h
#define PRO_DEF_PRE_OPERATOR_DISPATCH_WITH_DEFAULT(__NAME, __SIGN, __DEFFUNC) // see the implementation in proxy.h

#define PRO_DEF_POST_OPERATOR_DISPATCH(__NAME, __SIGN) // see the implementation in proxy.h
#define PRO_DEF_POST_OPERATOR_DISPATCH_WITH_DEFAULT(__NAME, __SIGN, __DEFFUNC) // see the implementation in proxy.h

#define PRO_DEF_CONVERTION_DISPATCH(__NAME, __T) // see the implementation in proxy.h
#define PRO_DEF_CONVERTION_DISPATCH_WITH_DEFAULT(__NAME, __T, __DEFFUNC) // see the implementation in proxy.h

Note that PRO_DEF_OPERATOR_DISPATCH() may not cover ALL forms of expressions with the given operator. For example, for an operand a, the plus sign + supports both prefix (+a, x + a) and postfix (a + x) forms. PRO_DEF_OPERATOR_DISPATCH() will only define the either prefix or the postfix (preferred) form when an operator supports both forms. People can explicitly choose whether an operator dispatch supports prefix or postfix form by using PRO_DEF_PRE_OPERATOR_DISPATCH() or PRO_DEF_POST_OPERATOR_DISPATCH(). The _WITH_DEFAULT version of the 3 macros allows implementations to provide additional default procedure if the operator is not applicable, similar with PRO_DEF_MEM_DISPATCH() and PRO_DEF_FREE_DISAPTCH().

Throughout the C++ standards, there are currently 45 different signs of operators (different operators may share the same sign, like * and &). The following 37 has been fully implemented in this change:

"+", "-", "*", "/", "%", "++", "--", "==", "!=", ">", "<", ">=", "<=", "<=>", "!", "&&", "||", "~", "&", "|", "^", "<<", ">>", "+=", "-=", "*=", "/=", "&=", "|=", "^=", "<<=", ">>=", ",", "->", "()", "[]", static_cast (type convertion)

The following 5 are context-dependent and not applicable for proxy:

"new", "new[]", "delete", "delete[]", "co_await"

The other 3 are not applicable:

  1. Assignment (=) is ambiguous in the context of proxy and therefore not implemented;
  2. Literals ("") only works for a limited number of primitive types and not applicable for proxy;
  3. operator->*() is used to access a member of an object through a pointer, which is considered to be implemented in later changes.
  • Unit test cases have been added for all the 37 different signs. Among them, 22 signs have both prefix and postfix forms:
"+", "-", "*", "/", "%", "++", "--", "==", "!=", ">", "<", ">=", "<=", "<=>", "&&", "||", "&", "|", "^", "<<", ">>", ","

@mingxwa mingxwa added this to the P3086R3 milestone May 31, 2024
@mingxwa mingxwa requested review from tian-lt and guominrui May 31, 2024 14:47
@mingxwa mingxwa self-assigned this May 31, 2024
@mingxwa mingxwa requested a review from lyf6lyf May 31, 2024 15:45
proxy.h Outdated Show resolved Hide resolved
@tian-lt tian-lt merged commit 83e766f into microsoft:main Jun 4, 2024
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/operator branch June 5, 2024 01:59
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.

Update README.md to reflect the new syntax to build a facade
2 participants