Implement P3016R6 Resolve Inconsistencies In begin/end For valarray And Braced Initializer Lists
Remove free function overloads of begin and end for initializer_list.
Replace free function overloads empty and data for initializer_list with member functions.
Replace free function overloads begin and end for valarray with member functions.
Provide new feature test macros __cpp_lib_initializer_list and __cpp_lib_valarray.
Resolves #5840
@microsoft-github-policy-service agree
Sections 4.1, most of 4.7 and 4.8 of the paper prescribe changes this STL already has (some #includes and noexcept/conditionally noexcept functions), so there was nothing to do.
Section 4.9 rewords the effects of some standard library member functions (mostly members of std::string), but they seem not relevant for the library implementation. Wording of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3016r6.html#wording-support.initlist defines data() as identical to begin(), so redefinition of other operations previously defined using begin() to data() has no effect IMO.
Do we want to actually change calls to _Ilist.begin() to _Ilist.data()? There are many other places, e.g. in <xstring>, where the (begin, size) pair is used instead of (data, size) required by the paper..
There are two failing tests (copied from CI):
std :: tests/Dev11_1074023_constexpr:37 (3864 of 7663)
libc++ :: std/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp
Dev11_1074023_constexpr fails on line 56
STATIC_ASSERT(begin(il) == end(il));
The test is compiled in C++14 mode. The removed non-member overload begin(initializer_list) used to be constexpr since C++14 (according to https://en.cppreference.com/w/cpp/utility/initializer_list/begin2.html), whereas the primary template wouldn't be constexpr until C++17 (https://en.cppreference.com/w/cpp/iterator/begin.html). Same issue for the libc++ test.
It appears that we either can't implement this change unconditionally, or we have to drop _CONSTEXPR17 from primary templates in <xutility> and replace it with unconditional constexpr. The third alternative (removing the failing test) does not seem appropriate.
For Dev11_1074023_constexpr, we can simply make that line of the test conditional on _HAS_CXX17.
For libc++, we can use tests/libcxx/expected_results.txt to mark the test as a known FAIL case until libc++ updates their implementation and corresponding test.
Do we want to actually change calls to
_Ilist.begin()to_Ilist.data()?
Under the As If Rule, we aren't required to, and I don't see the need to change this.
Status update (also for #5848): Your PRs are on my list of things to review (the STL Code Reviews project is my dashboard) but I will be delayed as I need to prioritize <flat_map> and <flat_set> soon. Just wanted to let you know that I'm not forgetting about them.