-
Notifications
You must be signed in to change notification settings - Fork 274
Deducing this for delegates #1553
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
Open
YexuanXiao
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
YexuanXiao:deducting-this-upstream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,23 @@ | ||
| set(CMAKE_CXX_STANDARD 23) | ||
|
|
||
| file(GLOB TEST_SRCS | ||
| LIST_DIRECTORIES false | ||
| CONFIGURE_DEPENDS | ||
| *.cpp | ||
| ) | ||
| list(FILTER TEST_SRCS EXCLUDE REGEX "/(main|pch)\\.cpp") | ||
|
|
||
| add_executable(test_cpp23 main.cpp ${TEST_SRCS}) | ||
|
|
||
| target_precompile_headers(test_cpp23 PRIVATE pch.h) | ||
| set_source_files_properties( | ||
| main.cpp | ||
| PROPERTIES SKIP_PRECOMPILE_HEADERS true | ||
| ) | ||
|
|
||
| add_dependencies(test_cpp23 build-cppwinrt-projection) | ||
|
|
||
| add_test( | ||
| NAME test_cpp23 | ||
| COMMAND "$<TARGET_FILE:test_cpp23>" ${TEST_COLOR_ARG} | ||
| ) |
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,123 @@ | ||
| #include "pch.h" | ||
|
|
||
| using namespace winrt; | ||
| using namespace Windows::Foundation::Collections; | ||
|
|
||
| #if defined(__cpp_explicit_this_parameter) && __cpp_explicit_this_parameter >= 202110L | ||
|
|
||
| TEST_CASE("delegate") | ||
| { | ||
| // <> | ||
| { | ||
| bool invoked = false; | ||
| delegate<> d = [&](this auto) { invoked = true; }; | ||
| d(); | ||
| REQUIRE(invoked); | ||
| } | ||
|
|
||
| // <int> | ||
| { | ||
| int result = 0; | ||
| delegate<int> d = [&](this auto, int a) { result = a; }; | ||
| d(123); | ||
| REQUIRE(result == 123); | ||
| } | ||
|
|
||
| // <int,int> | ||
| { | ||
| int result = 0; | ||
| delegate<int, int> d = [&](this auto, int a, int b) { result = a + b; }; | ||
| d(4,5); | ||
| REQUIRE(result == 9); | ||
| } | ||
|
|
||
| // void() | ||
| { | ||
| bool invoked = false; | ||
| delegate<void()> d = [&](this auto) { invoked = true; }; | ||
| d(); | ||
| REQUIRE(invoked); | ||
| } | ||
|
|
||
| // void(int) | ||
| { | ||
| int result = 0; | ||
| delegate<void(int)> d = [&](this auto, int a) { result = a; }; | ||
| d(123); | ||
| REQUIRE(result == 123); | ||
| } | ||
|
|
||
| // void(int,int) | ||
| { | ||
| int result = 0; | ||
| delegate<void(int,int)> d = [&](this auto, int a, int b) { result = a + b; }; | ||
| d(4, 5); | ||
| REQUIRE(result == 9); | ||
| } | ||
|
|
||
| // int() | ||
| { | ||
| delegate<int()> d = [](this auto) { return 123; }; | ||
| REQUIRE(d() == 123); | ||
| } | ||
|
|
||
| // int(int) | ||
| { | ||
| delegate<int(int)> d = [](this auto, int a) { return a; }; | ||
| REQUIRE(d(123) == 123); | ||
| } | ||
|
|
||
| // int(int,int) | ||
| { | ||
| delegate<int(int, int)> d = [](this auto, int a, int b) { return a + b; }; | ||
| REQUIRE(d(4, 5) == 9); | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("typedeventhandler") | ||
| { | ||
| using Handler = winrt::Windows::Foundation::TypedEventHandler<int, int>; | ||
|
|
||
| int called{}; | ||
| int sum{}; | ||
|
|
||
| Handler handler = [&called, &sum](this auto, int sender, int args) | ||
| { | ||
| ++called; | ||
| sum = sender + args; | ||
| }; | ||
|
|
||
| handler(1, 2); | ||
|
|
||
| REQUIRE(called == 1); | ||
| REQUIRE(sum == 3); | ||
| } | ||
|
|
||
| TEST_CASE("observablevector_vectorchanged") | ||
| { | ||
| IObservableVector<int> vector = single_threaded_observable_vector<int>(); | ||
|
|
||
| int called{}; | ||
| IObservableVector<int> observed_sender{ nullptr }; | ||
| CollectionChange change{}; | ||
| uint32_t index{}; | ||
|
|
||
| auto token = vector.VectorChanged([&](this auto, IObservableVector<int> sender, IVectorChangedEventArgs args) | ||
| { | ||
| ++called; | ||
| observed_sender = sender; | ||
| change = args.CollectionChange(); | ||
| index = args.Index(); | ||
| }); | ||
|
|
||
| vector.Append(123); | ||
|
|
||
| REQUIRE(called == 1); | ||
| REQUIRE(observed_sender == vector); | ||
| REQUIRE(change == CollectionChange::ItemInserted); | ||
| REQUIRE(index == 0); | ||
|
|
||
| vector.VectorChanged(token); | ||
| } | ||
|
|
||
| #endif |
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,30 @@ | ||
| #include <crtdbg.h> | ||
| #define CATCH_CONFIG_RUNNER | ||
|
|
||
| // Force reportFatal to be available on mingw-w64 | ||
| #define CATCH_CONFIG_WINDOWS_SEH | ||
|
|
||
| #if defined(_MSC_VER) | ||
| #pragma warning(disable : 5311) | ||
| #endif | ||
|
|
||
| #include "catch.hpp" | ||
| #include "winrt/base.h" | ||
|
|
||
| using namespace winrt; | ||
|
|
||
| int main(int const argc, char** argv) | ||
| { | ||
| init_apartment(); | ||
| std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); | ||
| _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); | ||
| (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | ||
| _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); | ||
| (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | ||
| return Catch::Session().run(argc, argv); | ||
| } | ||
|
|
||
| CATCH_TRANSLATE_EXCEPTION(hresult_error const& e) | ||
| { | ||
| return to_string(e.message()); | ||
| } |
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,2 @@ | ||
| #include "pch.h" | ||
|
|
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,10 @@ | ||
| #pragma once | ||
|
|
||
| #pragma warning(4: 4458) // ensure we compile clean with this warning enabled | ||
|
|
||
| #define WINRT_LEAN_AND_MEAN | ||
| #include "winrt/Windows.Foundation.h" | ||
| #include "winrt/Windows.Foundation.Collections.h" | ||
| #include "catch.hpp" | ||
|
|
||
| using namespace std::literals; |
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.