-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement P3016R6 Resolve Inconsistencies In begin/end For valarray And Braced Initializer Lists #5847
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
base: main
Are you sure you want to change the base?
Implement P3016R6 Resolve Inconsistencies In begin/end For valarray And Braced Initializer Lists #5847
Changes from 7 commits
d283bae
498ee1c
497704e
0887c8d
9a56b7e
ecc409a
b9c607a
1f660da
dcf8058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,9 @@ constexpr auto int64_max = numeric_limits<int64_t>::max(); | |
| constexpr initializer_list<int> il; | ||
| STATIC_ASSERT(il.size() == 0); | ||
| STATIC_ASSERT(il.begin() == il.end()); | ||
| #if _HAS_CXX17 | ||
| STATIC_ASSERT(begin(il) == end(il)); | ||
| #endif // _HAS_CXX17 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For archaeology:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No language lawyer here, so correct me if I am wrong, but the range-based for loop does not use the free function in this case, but rather the member begin/end. Those are marked as constexpr unconditionally (not only in C++14 onwards) in code. Link to cppinsights C++14 mode (very powerful argument for normal developers, not sure whether it is appropriate for STL development 😅 ) https://cppinsights.io/s/faddcfbd Nevertheless, I have added the for loop to the test suite and it compiles and executes in all modes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, you are right. Sorry. I must have been be confused with some |
||
|
|
||
| // TRANSITION, | ||
| // constexpr error_category() noexcept; | ||
|
|
||
| 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 | ||||||
|
||||||
| RUNALL_INCLUDE ..\usual_latest_matrix.lst | |
| RUNALL_INCLUDE ..\usual_matrix.lst |
Also, static_assert(e); is only standardized since C++17, so we need to write either static_assert(e, ""); or #define STATIC_ASSERT(__VA_ARGS__) static_assert(__VA_ARGS__, #__VA_ARGS__). The latter is widely used in MSVC STL's test suite.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <initializer_list> | ||
| #include <iterator> | ||
| #include <type_traits> | ||
| #include <valarray> | ||
|
|
||
| namespace my { | ||
|
|
||
| template <typename T> | ||
| void begin(std::initializer_list<T>); | ||
|
|
||
| template <typename T> | ||
| void end(std::initializer_list<T>); | ||
|
|
||
| template <typename T> | ||
| void empty(std::initializer_list<T>); | ||
|
|
||
| template <typename T> | ||
| void data(std::initializer_list<T>); | ||
| } // namespace my | ||
|
|
||
|
|
||
| int main() { | ||
| { | ||
| // Check that free functions in std can't be invoked with braced-initializer-list. | ||
| // If they could be invoked, the following expressions would be ambiguous between std:: and my:: | ||
| using namespace std; | ||
| using namespace my; | ||
| static_assert(std::is_same_v<decltype(begin({1, 2, 3})), void>); | ||
| static_assert(std::is_same_v<decltype(end({1, 2, 3})), void>); | ||
| static_assert(std::is_same_v<decltype(empty({1, 2, 3})), void>); | ||
| static_assert(std::is_same_v<decltype(data({1, 2, 3})), void>); | ||
| } | ||
|
|
||
| { | ||
| // Check that free functions in std still can be invoked on std::initializer_list | ||
| std::initializer_list<int> il = {1, 2, 3}; | ||
|
|
||
| using namespace std; | ||
| (void) begin(il); | ||
| (void) cbegin(il); | ||
| (void) end(il); | ||
| (void) cend(il); | ||
| (void) size(il); | ||
| (void) empty(il); | ||
| (void) data(il); | ||
| } | ||
|
|
||
| { | ||
| // Check that free functions in std can be invoked on std::valarray | ||
| std::valarray<int> v{1}; | ||
|
|
||
| using namespace std; | ||
| (void) begin(v); | ||
| (void) cbegin(v); // Did not compile before P3016R6 | ||
| (void) end(v); | ||
| (void) cend(v); // Did not compile before P3016R6 | ||
| (void) size(v); | ||
| // There are no members 'empty' and 'data' of valarray | ||
| // (void) empty(il); | ||
| // (void) data(il); | ||
| } | ||
| } |
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.
These should be moved to the C++14 section. And we should test them in
tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp.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.
Understood. Individual parts of yvals_core.h are sorted alphabetically, right? So I should prefer alphabetical sorting over smaller diff?
Tests in
tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cppdon't seem to be sorted, so I will just add new lines to the end.