-
Notifications
You must be signed in to change notification settings - Fork 1.6k
update the feature-test macro for P2162R2 for variant #2006
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
Merged
+102
−4
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d0be316
update the feature-test macro for P2162R2 for variant
fsb4000 14182f8
update the feature test macro test
fsb4000 d475618
update macro for __cpp_lib_variant for C++17 too as clang does.
fsb4000 44d359d
Disable libc++ test: language.support/support.limits/support.limits.g…
fsb4000 696d9ce
Add some tests based on P2162R2 examples
fsb4000 8b0824c
fix formatting
fsb4000 a231dfb
Add Licence comment
fsb4000 65eaf2f
change '/' to '\' in tests/libcxx/skipped_tests.txt
fsb4000 f6619b7
remove `std::` in test
fsb4000 4d9c248
Apply Casey Carter suggestions
fsb4000 d99a598
Code review feedback.
StephanTLavavej b88bfb3
Merge branch 'main' into 1683
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 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
4 changes: 4 additions & 0 deletions
4
tests/std/tests/P2162R2_std_visit_for_derived_classes_from_variant/env.lst
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,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\usual_17_matrix.lst |
84 changes: 84 additions & 0 deletions
84
tests/std/tests/P2162R2_std_visit_for_derived_classes_from_variant/test.cpp
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,84 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cassert> | ||
#include <memory> | ||
#include <utility> | ||
#include <variant> | ||
|
||
using namespace std; | ||
|
||
struct Disconnected { | ||
int val; | ||
}; | ||
|
||
struct Connecting { | ||
char val; | ||
}; | ||
|
||
struct Connected { | ||
double val; | ||
}; | ||
|
||
struct State : variant<Disconnected, Connecting, Connected> { | ||
using variant::variant; | ||
}; | ||
|
||
void example1_from_p2162r2() { | ||
State v1 = Disconnected{45}; | ||
const State v2 = Connecting{'d'}; | ||
visit([](auto x) { assert(x.val == 45); }, v1); | ||
visit([](auto x) { assert(x.val == 'd'); }, v2); | ||
visit([](auto x) { assert(x.val == 5.5); }, State{Connected{5.5}}); | ||
visit([](auto x) { assert(x.val == 45); }, move(v1)); | ||
visit([](auto x) { assert(x.val == 'd'); }, move(v2)); | ||
} | ||
|
||
fsb4000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
struct Expr; | ||
|
||
struct Neg { | ||
shared_ptr<Expr> expr; | ||
}; | ||
|
||
struct Add { | ||
shared_ptr<Expr> lhs; | ||
shared_ptr<Expr> rhs; | ||
}; | ||
|
||
struct Mul { | ||
shared_ptr<Expr> lhs; | ||
shared_ptr<Expr> rhs; | ||
}; | ||
|
||
struct Expr : variant<int, Neg, Add, Mul> { | ||
using variant::variant; | ||
}; | ||
|
||
int eval(const Expr& expr) { | ||
struct visitor { | ||
int operator()(int i) const { | ||
return i; | ||
} | ||
int operator()(const Neg& n) const { | ||
return -eval(*n.expr); | ||
} | ||
int operator()(const Add& a) const { | ||
return eval(*a.lhs) + eval(*a.rhs); | ||
} | ||
int operator()(const Mul& m) const { | ||
return eval(*m.lhs) * eval(*m.rhs); | ||
} | ||
}; | ||
return visit(visitor{}, expr); | ||
} | ||
|
||
fsb4000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void example2_from_p2162r2() { | ||
// (1) + (2*3) | ||
const Expr e = Add{make_shared<Expr>(1), make_shared<Expr>(Mul{make_shared<Expr>(2), make_shared<Expr>(3)})}; | ||
assert(eval(e) == (1 + 2 * 3)); | ||
} | ||
|
||
fsb4000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int main() { | ||
example1_from_p2162r2(); | ||
example2_from_p2162r2(); | ||
} |
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
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.