This repository was archived by the owner on Jan 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
Implement accessibility support for reflection #191
Merged
mingxwa
merged 7 commits into
microsoft:main
from
mingxwa:user/mingxwa/improve-reflection-a11y
Nov 11, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6cf7f2f
Implement accessibility support for reflection
mingxwa 4c006a7
Update docs
mingxwa 33e2d09
Remove redundant checks
mingxwa 1b76fcf
Rename accessor
mingxwa f68e5a9
Remove macro
mingxwa b09d3ae
Fix build
mingxwa 9a044f3
Update sample
mingxwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Macro `PRO_DEF_FREE_AS_MEM_DISPATCH` | ||
|
|
||
| ```cpp | ||
| #define PRO_DEF_FREE_AS_MEM_DISPATCH // see below | ||
| ``` | ||
|
|
||
| Macro `PRO_DEF_FREE_AS_MEM_DISPATCH` defines dispatch types for free function expressions with accessibility via a member function. It supports two syntaxes: | ||
|
|
||
| ```cpp | ||
| // (1) | ||
| PRO_DEF_FREE_AS_MEM_DISPATCH(dispatch_name, func_name); | ||
|
|
||
| // (2) | ||
| PRO_DEF_FREE_AS_MEM_DISPATCH(dispatch_name, func_name, accessibility_func_name); | ||
| ``` | ||
|
|
||
| `(1)` Equivalent to `PRO_DEF_FREE_AS_MEM_DISPATCH(dispatch_name, func_name, func_name);` | ||
|
|
||
| `(2)` Defines a class named `dispatch_name` of free function call expressions of `func_name` with accessibility via a member function. `dispatch_name` meets the [*ProAccessible*](ProAccessible.md) requirements of types `F`, `C`, and `Os...`, where `F` models concept [`facade`](facade.md), `C` is a tuple element type defined in `typename F::convention_types`, and each type `O` (possibly qualified with *cv ref noex*) in `Os...` is a tuple element type defined in `typename C::overload_types`. The member functions provided by `typename dispatch_name::template accessor<F, C, Os...>` are named `accessibility_func_name`. Let `SELF` be `std::forward<accessor cv ref>(*this)`, effectively equivalent to: | ||
|
|
||
| ```cpp | ||
| struct dispatch_name { | ||
| template <class T, class... Args> | ||
| decltype(auto) operator()(T&& self, Args&&... args) | ||
| noexcept(noexcept(func_name(std::forward<T>(self), std::forward<Args>(args)...))) | ||
| requires(requires { func_name(std::forward<T>(self), std::forward<Args>(args)...); }) { | ||
| return func_name(std::forward<T>(self), std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| template <class F, class C, class... Os> | ||
| struct accessor { | ||
| accessor() = delete; | ||
| }; | ||
| template <class F, class C, class... Os> | ||
| requires(sizeof...(Os) > 1u && (std::is_trivial_v<accessor<F, C, Os>> && ...)) | ||
| struct accessor<F, C, Os...> : accessor<F, C, Os>... { | ||
| using accessor<F, C, Os>::accessibility_func_name ...; | ||
| }; | ||
| template <class F, class C, class R, class... Args> | ||
| struct accessor<F, C, R(Args...) cv ref noex> { | ||
| R accessibility_func_name(Args... args) cv ref noex { | ||
| return pro::proxy_invoke<C, R(Args...) cv ref noex>(pro::access_proxy<F>(SELF), std::forward<Args>(args)...); | ||
| } | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| ```cpp | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include "proxy.h" | ||
|
|
||
| PRO_DEF_FREE_AS_MEM_DISPATCH(FreeToString, std::to_string, ToString); | ||
|
|
||
| struct Stringable : pro::facade_builder | ||
| ::add_convention<FreeToString, std::string()> | ||
| ::build {}; | ||
|
|
||
| int main() { | ||
| pro::proxy<Stringable> p = pro::make_proxy<Stringable>(123); | ||
| std::cout << p->ToString() << "\n"; // Prints: "123" | ||
| } | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [macro `PRO_DEF_FREE_DISPATCH`](PRO_DEF_FREE_DISPATCH.md) | ||
| - [alias template `basic_facade_builder::add_convention`](basic_facade_builder/add_convention.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Named requirements: *ProBasicReflection* | ||
|
|
||
| A type `R` meets the *ProBasicReflection* requirements if the following expressions are well-formed and have the specified semantics. | ||
|
|
||
| | Expressions | Semantics | | ||
| | ---------------------------- | ------------------------------------------------------------ | | ||
| | `R::is_direct` | A [core constant expression](https://en.cppreference.com/w/cpp/language/constant_expression) of type `bool`, specifying whether the reflection applies to a pointer type itself (`true`), or the element type of a pointer type (`false`). | | ||
| | `typename R::reflector_type` | A [trivial type](https://en.cppreference.com/w/cpp/named_req/TrivialType) that defines the data structure reflected from the type. | | ||
|
|
||
| ## See Also | ||
|
|
||
| - [*ProBasicFacade* requirements](ProBasicFacade.md) | ||
| - [*ProReflection* requirements](ProReflection.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.