-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<functional>
: Implement invoke_r
#2019
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0ab0cdc
Implement invoke_r
SuperWig 4ef0e40
trailing spaces
SuperWig 88caed6
if constexpr for void
SuperWig c0d78ba
Add zero argument and void return type functionality.
SuperWig f376138
[skip ci] formatting
SuperWig 1c53570
Add _NODISCARD
SuperWig 4a91928
[skip ci] correct comment placement and `()`
SuperWig 9a30dfd
[skip ci] formatting
SuperWig 6b1dde4
Restore 3 arg overload.
SuperWig 059fdba
Use invoke_r on data member and use is_permissive trick.
SuperWig 1963a65
Make a templated noexcept_test
SuperWig 795d2a8
Merge branch 'main' into invoke_r
StephanTLavavej 78abdc7
Small changes
SuperWig 27ecd63
[skip ci] SHOUTY banner
SuperWig edc4e15
Use single overload
SuperWig 554e25e
Use SFINAE instead of requires
SuperWig b5d2606
long int and foo
SuperWig 64f3d30
use traits and add additional noexcept test
SuperWig 46fa210
additional tests
SuperWig e169e27
Missed argument overloads
SuperWig b197c7d
Test noexcept functions are false if __cpp_noexcept_function_type isn…
SuperWig 45a3d89
Assert messages are no longer correct.
SuperWig f491133
Merge remote-tracking branch 'upstream/main' into invoke_r
SuperWig d2018be
[skip ci] shhh
SuperWig 92cd950
Merge branch 'main' into invoke_r
StephanTLavavej 56bc89f
Test a stateful lambda.
StephanTLavavej f2ede72
Need to include `<string>`.
StephanTLavavej 021209d
Consistently use `STATIC_ASSERT`.
StephanTLavavej 1ab5964
Use `static_cast<T&&>` for throughput/consistency.
StephanTLavavej 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\usual_latest_matrix.lst |
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,115 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cassert> | ||
#include <functional> | ||
#include <string> | ||
#include <type_traits> | ||
|
||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) | ||
|
||
using namespace std; | ||
|
||
// TRANSITION, DevCom-1457457 | ||
namespace detail { | ||
static constexpr bool permissive() { | ||
return false; | ||
} | ||
|
||
template <class> | ||
struct DependentBase { | ||
static constexpr bool permissive() { | ||
return true; | ||
} | ||
}; | ||
|
||
template <class T> | ||
struct Derived : DependentBase<T> { | ||
static constexpr bool test() { | ||
return permissive(); | ||
} | ||
}; | ||
} // namespace detail | ||
constexpr bool is_permissive = detail::Derived<int>::test(); | ||
|
||
constexpr int square(int n) { | ||
return n * n; | ||
} | ||
constexpr int square_noexcept(int n) noexcept { | ||
return n * n; | ||
} | ||
constexpr const char* cstring() noexcept; | ||
|
||
struct Thing { | ||
int n = 0; | ||
constexpr int& moo() { | ||
return n; | ||
} | ||
}; | ||
|
||
struct RefQualified { | ||
constexpr int operator()(int&&) && { | ||
return 1; | ||
} | ||
constexpr int operator()(const int&) && { | ||
return 2; | ||
} | ||
constexpr int operator()(int&&) & { | ||
return 3; | ||
} | ||
constexpr int operator()(const int&) & { | ||
return 4; | ||
} | ||
}; | ||
|
||
constexpr bool test_invoke_r() { | ||
auto v1 = invoke_r<long>(square, 3); | ||
assert(v1 == 9L); | ||
STATIC_ASSERT(is_same_v<decltype(v1), long>); | ||
|
||
auto v2 = invoke_r<double>([]() -> int { return 5; }); | ||
assert(v2 == 5); | ||
STATIC_ASSERT(is_same_v<decltype(v2), double>); | ||
STATIC_ASSERT(is_void_v<decltype(invoke_r<void>(square, 1))>); | ||
|
||
// TRANSITION, DevCom-1457457 | ||
STATIC_ASSERT(noexcept(invoke_r<int>(square, 3)) == is_permissive); | ||
STATIC_ASSERT(noexcept(invoke(square, 3)) == is_permissive); | ||
|
||
constexpr bool has_noexcept_in_type = | ||
#ifdef __cpp_noexcept_function_type | ||
true; | ||
#else | ||
false; | ||
#endif | ||
SuperWig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
STATIC_ASSERT(noexcept(invoke(square_noexcept, 3)) == has_noexcept_in_type); | ||
STATIC_ASSERT(noexcept(invoke_r<int>(square_noexcept, 3)) == has_noexcept_in_type); | ||
STATIC_ASSERT(noexcept(invoke(cstring)) == has_noexcept_in_type); | ||
STATIC_ASSERT(!noexcept(invoke_r<string>(cstring))); | ||
|
||
Thing thing; | ||
invoke_r<void>(&Thing::n, thing); // no nodiscard warning | ||
STATIC_ASSERT(is_same_v<decltype(invoke(&Thing::moo, thing)), int&>); | ||
STATIC_ASSERT(is_same_v<decltype(invoke_r<int>(&Thing::moo, thing)), int>); | ||
|
||
auto lambda = [counter = 0]() mutable { return ++counter; }; | ||
assert(lambda() == 1); | ||
assert(lambda() == 2); | ||
assert(invoke_r<int>(lambda) == 3); | ||
assert(invoke_r<int>(lambda) == 4); | ||
assert(lambda() == 5); | ||
|
||
int lvalue = 0; | ||
assert(invoke_r<int>(RefQualified{}, 0) == 1); | ||
assert(invoke_r<int>(RefQualified{}, lvalue) == 2); | ||
RefQualified r; | ||
assert(invoke_r<int>(r, 0) == 3); | ||
assert(invoke_r<int>(r, lvalue) == 4); | ||
|
||
return true; | ||
} | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int main() { | ||
test_invoke_r(); | ||
STATIC_ASSERT(test_invoke_r()); | ||
} |
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
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.
HUGE nit: the paper title does not seem to have the parenthesis
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.
Good catch - this is intentional, I added the parentheses to the "cleaned-up" title in #1978 to be consistent with the other cleaned-up titles.