-
Notifications
You must be signed in to change notification settings - Fork 155
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
Revise design of conversion_dispatch
#212
Merged
mingxwa
merged 4 commits into
microsoft:main
from
mingxwa:user/mingxwa/conversion-dispatch
Dec 9, 2024
Merged
Changes from all commits
Commits
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 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,44 @@ | ||
# Class `explicit_conversion_dispatch` | ||
|
||
```cpp | ||
class explicit_conversion_dispatch; | ||
|
||
using conversion_dispatch = explicit_conversion_dispatch; | ||
``` | ||
|
||
Class `explicit_conversion_dispatch` models a [dispatch](ProDispatch.md) type for explicit type conversion expressions. It meets the [*ProAccessible* requirements](ProAccessible.md) of applicable types. `conversion_dispatch` is an alias of `explicit_conversion_dispatch`. | ||
|
||
## Member Functions | ||
|
||
| Name | Description | | ||
| ------------------------------------------------------------ | --------------------------------------------------- | | ||
| (constructor) [nothrow] | constructs an `explicit_conversion_dispatch` object | | ||
| [`operator()`](explicit_conversion_dispatch/operator_call.md) | invokes the dispatch | | ||
|
||
## Member Types | ||
|
||
| Name | Description | | ||
| ------------------------------------------------------ | --------------------------------- | | ||
| [`accessor`](explicit_conversion_dispatch/accessor.md) | provides accessibility to `proxy` | | ||
|
||
## Example | ||
|
||
```cpp | ||
#include <iostream> | ||
|
||
#include "proxy.h" | ||
|
||
struct IntConvertible : pro::facade_builder | ||
::add_convention<pro::conversion_dispatch, int() const> | ||
::build {}; | ||
|
||
int main() { | ||
pro::proxy<IntConvertible> p = pro::make_proxy<IntConvertible, short>(123); // p holds a short | ||
std::cout << static_cast<int>(*p) << "\n"; // Prints: "123" | ||
} | ||
``` | ||
|
||
## See Also | ||
|
||
- [class `implicit_conversion_dispatch`](implicit_conversion_dispatch.md) | ||
- [class template `operator_dispatch`](operator_dispatch.md) |
This file contains 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,30 @@ | ||
# Class template `explicit_conversion_dispatch::accessor` | ||
|
||
```cpp | ||
// (1) | ||
template <class F, class C, class... Os> | ||
struct accessor { | ||
accessor() = delete; | ||
}; | ||
|
||
// (2) | ||
template <class F, class C, class... Os> | ||
requires(sizeof...(Os) > 1u && (std::is_constructible_v<accessor<F, C, Os>> && ...)) | ||
struct accessor<F, C, Os...> : accessor<F, C, Os>... { | ||
using accessor<F, C, Os>::operator return-type-of<Os>...; | ||
}; | ||
|
||
// (3) | ||
template <class F, class C> | ||
struct accessor<F, C, T() cv ref noex> { | ||
explicit operator T() cv ref noex; | ||
}; | ||
``` | ||
|
||
Let `SELF` be `std::forward<accessor cv ref>(*this)`. | ||
|
||
`(1)` The default implementation of `accessor` is not constructible. | ||
|
||
`(2)` When `sizeof...(Os)` is greater than `1`, and `accessor<F, C, Os>...` are default-constructible, inherits all `accessor<F, C, Os>...` types and `using` their `operator return-type-of<Os>`. `return-type-of<O>` denotes the *return type* of the overload type `O`. | ||
|
||
`(3)` When `sizeof...(Os)` is `1` and the only type `O` in `Os` is `T() cv ref noex`, provides an explicit `operator T()` with the same *cv ref noex* specifiers. `accessor::operator T()` is equivalent to `return proxy_invoke<C, T() cv ref noex>(access_proxy<F>(SELF))`. |
This file contains 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,8 @@ | ||
# `explicit_conversion_dispatch::operator()` | ||
|
||
```cpp | ||
template <class T> | ||
/* see below */ operator()(T&& value) noexcept; | ||
``` | ||
|
||
Returns a value that is implicitly convertible to any type `U` with expression `U{std::forward<T>(value)}` when `T` is explicitly convertible to type `U`. |
This file contains 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,57 @@ | ||
# Class `implicit_conversion_dispatch` | ||
|
||
```cpp | ||
class explicit_conversion_dispatch; | ||
``` | ||
|
||
Class `implicit_conversion_dispatch` models a [dispatch](ProDispatch.md) type for implicit type conversion expressions. It meets the [*ProAccessible* requirements](ProAccessible.md) of applicable types. | ||
|
||
## Member Functions | ||
|
||
| Name | Description | | ||
| ------------------------------------------------------------ | --------------------------------------------------- | | ||
| (constructor) [nothrow] | constructs an `implicit_conversion_dispatch` object | | ||
| [`operator()`](implicit_conversion_dispatch/operator_call.md) | invokes the dispatch | | ||
|
||
## Member Types | ||
|
||
| Name | Description | | ||
| ------------------------------------------------------ | --------------------------------- | | ||
| [`accessor`](implicit_conversion_dispatch/accessor.md) | provides accessibility to `proxy` | | ||
|
||
## Example | ||
|
||
```cpp | ||
#include <iomanip> | ||
#include <iostream> | ||
|
||
#include "proxy.h" | ||
|
||
struct Runnable : pro::facade_builder | ||
::add_convention<pro::operator_dispatch<"()">, void()> | ||
::build {}; | ||
|
||
struct CopyableRunnable : pro::facade_builder | ||
::support_copy<pro::constraint_level::nontrivial> | ||
::add_facade<Runnable> | ||
::add_direct_convention<pro::implicit_conversion_dispatch, | ||
pro::proxy<Runnable>() const&, pro::proxy<Runnable>() &&> | ||
::build {}; | ||
|
||
int main() { | ||
pro::proxy<CopyableRunnable> p1 = pro::make_proxy<CopyableRunnable>( | ||
[] { std::cout << "Lambda expression invoked\n"; }); | ||
auto p2 = p1; // Copy construction | ||
pro::proxy<Runnable> p3 = p2; // Implicit conversion via const reference of pro::proxy<CopyableRunnable> | ||
std::cout << std::boolalpha << p2.has_value() << "\n"; // Prints: "true" | ||
// auto p4 = p3; // Won't compile because pro::proxy<Runnable> is not copy-constructible | ||
pro::proxy<Runnable> p5 = std::move(p2); // Implicit conversion via rvalue reference of pro::proxy<CopyableRunnable> | ||
std::cout << p2.has_value() << "\n"; // Prints: "false" | ||
(*p5)(); // Prints: "Lambda expression invoked" | ||
} | ||
``` | ||
|
||
## See Also | ||
|
||
- [class `explicit_conversion_dispatch`](explicit_conversion_dispatch.md) | ||
- [class template `operator_dispatch`](operator_dispatch.md) |
This file contains 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,30 @@ | ||
# Class template `implicit_conversion_dispatch::accessor` | ||
|
||
```cpp | ||
// (1) | ||
template <class F, class C, class... Os> | ||
struct accessor { | ||
accessor() = delete; | ||
}; | ||
|
||
// (2) | ||
template <class F, class C, class... Os> | ||
requires(sizeof...(Os) > 1u && (std::is_constructible_v<accessor<F, C, Os>> && ...)) | ||
struct accessor<F, C, Os...> : accessor<F, C, Os>... { | ||
using accessor<F, C, Os>::operator return-type-of<Os>...; | ||
}; | ||
|
||
// (3) | ||
template <class F, class C> | ||
struct accessor<F, C, T() cv ref noex> { | ||
operator T() cv ref noex; | ||
}; | ||
``` | ||
|
||
Let `SELF` be `std::forward<accessor cv ref>(*this)`. | ||
|
||
`(1)` The default implementation of `accessor` is not constructible. | ||
|
||
`(2)` When `sizeof...(Os)` is greater than `1`, and `accessor<F, C, Os>...` are default-constructible, inherits all `accessor<F, C, Os>...` types and `using` their `operator return-type-of<Os>`. `return-type-of<O>` denotes the *return type* of the overload type `O`. | ||
|
||
`(3)` When `sizeof...(Os)` is `1` and the only type `O` in `Os` is `T() cv ref noex`, provides an implicit `operator T()` with the same *cv ref noex* specifiers. `accessor::operator T()` is equivalent to `return proxy_invoke<C, T() cv ref noex>(access_proxy<F>(SELF))`. | ||
mingxwa marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,8 @@ | ||
# `implicit_conversion_dispatch::operator()` | ||
|
||
```cpp | ||
template <class T> | ||
T&& operator()(T&& value) noexcept; | ||
``` | ||
|
||
Returns `std::forward<T>(value)`. |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implicit_conversion_dispatch?