[libcxx-commits] [libcxx] [libc++] P3016R6: Resolve inconsistencies in begin/end for `valarray` and braced initializer lists (PR #173637)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Dec 26 08:20:21 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: A. Jiang (frederick-vs-ja)
<details>
<summary>Changes</summary>
This paper is implemented as a Defect Report against C++11 and later revisions.
- Inclusion of `<typeinfo>` in `<functional>` should be considered as a patch to C++ TR1 [N1836](https://wg21.link/N1836), while the related parts were merged into C++11.
- Changes of `initializer_list` should be considered as a patch to C++11 paper [N2672](https://wg21.link/n2672).
- Changes of `valarray`, `std::begin`, and `std::end` and availability of range access functions in `<valarray>` should be considered as a patch to C++11 paper [N2930](https://wg21.link/n2930).
- Inclusion of `<typeinfo>` in `<typeindex>` should be considered as a patch to C++11 paper [N2932](https://wg21.link/n2932).
- Changes of `std::cbegin`, `std::cend`, `std::rbegin`, `std::rend`, `std::crbegin`, and `std::crend` and the inclusion of `<initializer_list>` in `<iterator>` should be considered as a patch to [LWG2128](https://wg21.link/lwg2128), while LWG2128 is consistently considered to be a pure feature addition in C++14 by implementations.
- Changes of `std::data`, `std::empty`, and `std::size` should be considered as a patch to C++17 paper [N4280](https://wg21.link/n4280).
- Inclusion of `<initializer_list>` and `<typeinfo>` in `<any>` should be considered as a patch to C++17 paper [P0220R1](https://wg21.link/p0220r1).
- Changes of `std::ssize` should be considered as a patch to C++20 paper [P1227R2](https://wg21.link/p1227r2).
- Inclusion of `<initializer_list>` in `<functional>` should be considered as a patch to C++23 paper [P0288R9](https://wg21.link/p0288r9).
- Availability of range access functions in `<stacktrace>` should be considered as a patch to C++23 paper [P0881R7](https://wg21.link/p0881r7).
- Availability of range access functions in `<optional>` should be considered as a patch to C++26 paper [P3168R2](https://wg21.link/p3168r2).
Notes for backported and missing parts:
- Changes of `<stacktrace>` are not implemented because P0881R7 is not implemented. But I think P3016R6 should be considered complete, with note added.
- `constexpr` for member functions of `initializer_list` is only added since C++14, in the spirit of C++14 paper [N3471](https://wg21.link/n3471).
- Changes of inclusions and `valarray` are unconditionally implemented, which follows the current convention of libc++.
Drive-by changes:
- Conditionally strengthen the constructor of `reverse_iterator` from the underlying iterator, because many (un)conditionally `noexcept` functions call that constructor now.
Fixes #<!-- -->171271.
---
Patch is 87.19 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/173637.diff
40 Files Affected:
- (modified) libcxx/docs/FeatureTestMacroTable.rst (+4)
- (modified) libcxx/docs/ReleaseNotes/22.rst (+2)
- (modified) libcxx/docs/Status/Cxx2cPapers.csv (+1-1)
- (modified) libcxx/include/__iterator/access.h (+16-8)
- (modified) libcxx/include/__iterator/reverse_access.h (+30-16)
- (modified) libcxx/include/__iterator/reverse_iterator.h (+6-2)
- (modified) libcxx/include/any (+6-1)
- (modified) libcxx/include/functional (+8-2)
- (modified) libcxx/include/initializer_list (+10-13)
- (modified) libcxx/include/iterator (+35-24)
- (modified) libcxx/include/optional (+8)
- (modified) libcxx/include/typeindex (+4-1)
- (modified) libcxx/include/valarray (+27-49)
- (modified) libcxx/include/version (+4)
- (modified) libcxx/modules/std/initializer_list.inc (-4)
- (modified) libcxx/modules/std/valarray.inc (-3)
- (modified) libcxx/test/libcxx/language.support/nodiscard.verify.cpp (+2)
- (modified) libcxx/test/libcxx/numerics/numarray/nodiscard.verify.cpp (+5-5)
- (modified) libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp (+4-2)
- (modified) libcxx/test/std/iterators/iterator.container/data.pass.cpp (+4-5)
- (modified) libcxx/test/std/iterators/iterator.container/empty.pass.cpp (+4-5)
- (modified) libcxx/test/std/iterators/iterator.container/size.pass.cpp (+8-8)
- (modified) libcxx/test/std/iterators/iterator.container/ssize.pass.cpp (+14-14)
- (modified) libcxx/test/std/iterators/iterator.range/begin-end.array.pass.cpp (+8-2)
- (modified) libcxx/test/std/iterators/iterator.range/begin-end.container.pass.cpp (+168-11)
- (modified) libcxx/test/std/iterators/iterator.range/begin-end.initializer_list.pass.cpp (+6-4)
- (modified) libcxx/test/std/iterators/iterator.range/mandatory_inclusions.gen.py (+5-2)
- (modified) libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.iter.pass.cpp (+10-2)
- (modified) libcxx/test/std/language.support/support.initlist/support.initlist.access/access.pass.cpp (+63-26)
- (removed) libcxx/test/std/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp (-68)
- (added) libcxx/test/std/language.support/support.limits/support.limits.general/initializer_list.version.compile.pass.cpp (+74)
- (added) libcxx/test/std/language.support/support.limits/support.limits.general/valarray.version.compile.pass.cpp (+74)
- (modified) libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp (+78)
- (added) libcxx/test/std/numerics/numarray/template.valarray/types.compile.pass.cpp (+53)
- (removed) libcxx/test/std/numerics/numarray/template.valarray/types.pass.cpp (-29)
- (added) libcxx/test/std/numerics/numarray/template.valarray/valarray.members/begin-end.pass.cpp (+82)
- (removed) libcxx/test/std/numerics/numarray/valarray.range/begin-end.pass.cpp (-69)
- (modified) libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp (+2-2)
- (modified) libcxx/utils/generate_feature_test_macro_components.py (+10)
- (modified) libcxx/utils/libcxx/header_information.py (+4-2)
``````````diff
diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index 32911d0f64449..dca2c7747ccae 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -34,6 +34,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_generic_associative_lookup`` ``201304L``
---------------------------------------------------------- -----------------
+ ``__cpp_lib_initializer_list`` ``202511L``
+ ---------------------------------------------------------- -----------------
``__cpp_lib_integer_sequence`` ``201304L``
---------------------------------------------------------- -----------------
``__cpp_lib_integral_constant_callable`` ``201304L``
@@ -66,6 +68,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_tuples_by_type`` ``201304L``
---------------------------------------------------------- -----------------
+ ``__cpp_lib_valarray`` ``202511L``
+ ---------------------------------------------------------- -----------------
**C++17**
----------------------------------------------------------------------------
``__cpp_lib_addressof_constexpr`` ``201603L``
diff --git a/libcxx/docs/ReleaseNotes/22.rst b/libcxx/docs/ReleaseNotes/22.rst
index 0d1a1fbc00f2c..abf81e3fff94a 100644
--- a/libcxx/docs/ReleaseNotes/22.rst
+++ b/libcxx/docs/ReleaseNotes/22.rst
@@ -50,6 +50,8 @@ Implemented Papers
(`Github <https://llvm.org/PR105381>`__)
- P2835R7: Expose ``std::atomic_ref``'s object address (`Github <https://llvm.org/PR118377>`__)
- P2944R3: Comparisons for ``reference_wrapper`` (`Github <https://llvm.org/PR105424>`__)
+- P3016R6: Resolve inconsistencies in begin/end for ``valarray`` and braced initializer lists
+ (`Github <https://llvm.org/PR171271>`__)
- P3168R2: Give ``std::optional`` Range Support (`Github <https://llvm.org/PR105430>`__)
- P3567R2: ``flat_meow`` Fixes (`Github <https://llvm.org/PR162022>`__)
- P3836R2: Make ``optional<T&>`` trivially copyable (`Github <https://llvm.org/PR171275>`__)
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 9bb5d2bda3d4d..dce772eae7b53 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -158,7 +158,7 @@
"`P1317R2 <https://wg21.link/P1317R2>`__","Remove return type deduction in ``std::apply``","2025-06 (Sofia)","","","`#148183 <https://github.com/llvm/llvm-project/issues/148183>`__",""
"","","","","","",""
"`P3920R0 <https://wg21.link/P3920R0>`__","Wording for NB comment resolution on trivial relocation","2025-11 (Kona)","|Nothing To Do|","","`#171269 <https://github.com/llvm/llvm-project/issues/171269>`__",""
-"`P3016R6 <https://wg21.link/P3016R6>`__","Resolve inconsistencies in begin/end for ``valarray`` and braced initializer lists","2025-11 (Kona)","","","`#171271 <https://github.com/llvm/llvm-project/issues/171271>`__",""
+"`P3016R6 <https://wg21.link/P3016R6>`__","Resolve inconsistencies in begin/end for ``valarray`` and braced initializer lists","2025-11 (Kona)","|Complete|","22","`#171271 <https://github.com/llvm/llvm-project/issues/171271>`__","Implemented as a DR against C++11. Change of ``<stacktrace>`` is blocked on `P0881R7 <https://wg21.link/P0881R7>`__."
"`P3567R2 <https://wg21.link/P3567R2>`__","``flat_meow`` Fixes","2025-11 (Kona)","|Complete|","22","`#171272 <https://github.com/llvm/llvm-project/issues/171272>`__",""
"`P3663R3 <https://wg21.link/P3663R3>`__","Future-proof ``submdspan_mapping``","2025-11 (Kona)","","","`#166089 <https://github.com/llvm/llvm-project/issues/166089>`__",""
"`P3914R0 <https://wg21.link/P3914R0>`__","Assorted NB comment resolutions for Kona 2025","2025-11 (Kona)","","","`#171274 <https://github.com/llvm/llvm-project/issues/171274>`__",""
diff --git a/libcxx/include/__iterator/access.h b/libcxx/include/__iterator/access.h
index d42855f925487..209f249f79d2d 100644
--- a/libcxx/include/__iterator/access.h
+++ b/libcxx/include/__iterator/access.h
@@ -32,23 +32,31 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT
#if !defined(_LIBCPP_CXX03_LANG)
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) {
- return __c.begin();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) //
+ noexcept(noexcept(__c.begin())) //
+ -> decltype(/*-*/ __c.begin()) {
+ return /*--------*/ __c.begin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) -> decltype(__c.begin()) {
- return __c.begin();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) //
+ noexcept(noexcept(__c.begin())) //
+ -> decltype(/*-*/ __c.begin()) {
+ return /*--------*/ __c.begin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) {
- return __c.end();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) //
+ noexcept(noexcept(__c.end())) //
+ -> decltype(/*-*/ __c.end()) {
+ return /*--------*/ __c.end();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) {
- return __c.end();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) //
+ noexcept(noexcept(__c.end())) //
+ -> decltype(/*-*/ __c.end()) {
+ return /*--------*/ __c.end();
}
# if _LIBCPP_STD_VER >= 14
diff --git a/libcxx/include/__iterator/reverse_access.h b/libcxx/include/__iterator/reverse_access.h
index f6e60c3fb75b3..ae1ebe98e1a36 100644
--- a/libcxx/include/__iterator/reverse_access.h
+++ b/libcxx/include/__iterator/reverse_access.h
@@ -23,53 +23,67 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 14
template <class _Tp, size_t _Np>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) noexcept {
return reverse_iterator<_Tp*>(__array + _Np);
}
template <class _Tp, size_t _Np>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) noexcept {
return reverse_iterator<_Tp*>(__array);
}
template <class _Ep>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*>
+rbegin(initializer_list<_Ep> __il) noexcept {
return reverse_iterator<const _Ep*>(__il.end());
}
template <class _Ep>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*>
+rend(initializer_list<_Ep> __il) noexcept {
return reverse_iterator<const _Ep*>(__il.begin());
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) {
- return __c.rbegin();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) //
+ noexcept(noexcept(__c.rbegin())) //
+ -> decltype(/*-*/ __c.rbegin()) {
+ return /*--------*/ __c.rbegin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) {
- return __c.rbegin();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) //
+ noexcept(noexcept(__c.rbegin())) //
+ -> decltype(/*-*/ __c.rbegin()) {
+ return /*--------*/ __c.rbegin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) {
- return __c.rend();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) //
+ noexcept(noexcept(__c.rend())) //
+ -> decltype(/*-*/ __c.rend()) {
+ return /*--------*/ __c.rend();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) -> decltype(__c.rend()) {
- return __c.rend();
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) //
+ noexcept(noexcept(__c.rend())) //
+ -> decltype(/*-*/ __c.rend()) {
+ return /*--------*/ __c.rend();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) -> decltype(std::rbegin(__c)) {
- return std::rbegin(__c);
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) //
+ noexcept(noexcept(std::rbegin(__c))) //
+ -> decltype(/*-*/ std::rbegin(__c)) {
+ return /*--------*/ std::rbegin(__c);
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) -> decltype(std::rend(__c)) {
- return std::rend(__c);
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) //
+ noexcept(noexcept(std::rend(__c))) //
+ -> decltype(/*-*/ std::rend(__c)) {
+ return /*--------*/ std::rend(__c);
}
#endif // _LIBCPP_STD_VER >= 14
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 834695dd16703..dd6455b91f6d3 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -89,7 +89,9 @@ class reverse_iterator
#ifndef _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator() : __t_(), current() {}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit reverse_iterator(_Iter __x) : __t_(__x), current(__x) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit reverse_iterator(_Iter __x)
+ _NOEXCEPT_(is_nothrow_constructible<_Iter, _Iter&>::value)
+ : __t_(__x), current(__x) {}
template <class _Up, __enable_if_t<!is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator(const reverse_iterator<_Up>& __u)
@@ -106,7 +108,9 @@ class reverse_iterator
#else
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator() : current() {}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit reverse_iterator(_Iter __x) : current(__x) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit reverse_iterator(_Iter __x)
+ _NOEXCEPT_(is_nothrow_constructible<_Iter, _Iter&>::value)
+ : current(__x) {}
template <class _Up, __enable_if_t<!is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator(const reverse_iterator<_Up>& __u)
diff --git a/libcxx/include/any b/libcxx/include/any
index 5c779e397c9ea..ffe5297b9a22d 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -13,6 +13,9 @@
/*
any synopsis
+#include <initializer_list>
+#include <typeinfo>
+
namespace std {
class bad_any_cast : public bad_cast
@@ -106,9 +109,11 @@ namespace std {
# include <__utility/move.h>
# include <__utility/unreachable.h>
# include <__verbose_abort>
+# include <version>
+
+// standard-mandated includes
# include <initializer_list>
# include <typeinfo>
-# include <version>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
diff --git a/libcxx/include/functional b/libcxx/include/functional
index 9ebcd818ec840..f8169608d1c60 100644
--- a/libcxx/include/functional
+++ b/libcxx/include/functional
@@ -13,6 +13,9 @@
/*
functional synopsis
+#include <initializer_list>
+#include <typeinfo>
+
namespace std
{
@@ -582,7 +585,6 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
# include <array>
-# include <initializer_list>
# include <unordered_map>
# endif
@@ -596,7 +598,6 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# include <stdexcept>
# include <tuple>
# include <type_traits>
-# include <typeinfo>
# include <utility>
# include <vector>
# endif
@@ -604,6 +605,11 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 23
# include <__vector/vector.h>
# endif
+
+// standard-mandated includes
+# include <initializer_list>
+# include <typeinfo>
+
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
#endif // _LIBCPP_FUNCTIONAL
diff --git a/libcxx/include/initializer_list b/libcxx/include/initializer_list
index 44cd45668388b..f8c0abcfbd3f3 100644
--- a/libcxx/include/initializer_list
+++ b/libcxx/include/initializer_list
@@ -30,14 +30,13 @@ public:
initializer_list() noexcept; // constexpr in C++14
+ const E* data() const noexcept; // constexpr in C++14
size_t size() const noexcept; // constexpr in C++14
+ bool empty() const noexcept; // constexpr in C++14
const E* begin() const noexcept; // constexpr in C++14
const E* end() const noexcept; // constexpr in C++14
};
-template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
-template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
-
} // std
*/
@@ -78,10 +77,18 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* data() const noexcept {
+ return __begin_;
+ }
+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t size() const _NOEXCEPT {
return __size_;
}
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool empty() const noexcept {
+ return __size_ == 0;
+ }
+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* begin() const _NOEXCEPT {
return __begin_;
}
@@ -91,16 +98,6 @@ public:
}
};
-template <class _Ep>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* begin(initializer_list<_Ep> __il) _NOEXCEPT {
- return __il.begin();
-}
-
-template <class _Ep>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* end(initializer_list<_Ep> __il) _NOEXCEPT {
- return __il.end();
-}
-
# endif // !defined(_LIBCPP_CXX03_LANG)
} // namespace std
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index fc8bdc5e6bcf6..4355c529cca22 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -13,7 +13,9 @@
/*
iterator synopsis
+#include <compare>
#include <concepts>
+#include <initializer_list>
namespace std
{
@@ -639,41 +641,49 @@ public:
bool failed() const noexcept;
};
-template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); // constexpr since C++17
-template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); // constexpr since C++17
-template <class C> constexpr auto end(C& c) -> decltype(c.end()); // constexpr since C++17
-template <class C> constexpr auto end(const C& c) -> decltype(c.end()); // constexpr since C++17
+template <class C> constexpr auto begin(C& c) noexcept(see-below) -> decltype(c.begin()); // constexpr since C++17
+template <class C> constexpr auto begin(const C& c) noexcept(see-below) -> decltype(c.begin()); // constexpr since C++17
+template <class C> constexpr auto end(C& c) noexcept(see-below) -> decltype(c.end()); // constexpr since C++17
+template <class C> constexpr auto end(const C& c) noexcept(see-below) -> decltype(c.end()); // constexpr since C++17
template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
template <class C> constexpr auto cbegin(const C& c) noexcept(see-below) -> decltype(std::begin(c)); // C++14
template <class C> constexpr auto cend(const C& c) noexcept(see-below) -> decltype(std::end(c)); // C++14
-template <class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin()); // C++14, constexpr since C++17
-template <class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14, constexpr since C++17
-template <class C> constexpr auto rend(C& c) -> decltype(c.rend()); // C++14, constexpr since C++17
-template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14, constexpr since C++17
-template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14, constexpr since C++17
-template <class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il); // C++14, constexpr since C++17
-template <class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]); // C++14, constexpr since C++17
-template <class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]); // C++14, constexpr since C++17
-template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14, constexpr since C++17
-template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14, constexpr since C++17
+template <class C>
+constexpr auto rbegin(C& c) noexcept(see-below) -> decltype(c.rbegin()); // C++14, constexpr since C++17
+template <class C>
+constexpr auto rbegin(const C& c) noexcept(see-below) -> decltype(c.rbegin()); // C++14, constexpr since C++17
+template <class C>
+constexpr auto rend(C& c) noexcept(see-below) -> decltype(c.rend()); // C++14, constexpr since C++17
+template <class C>
+constexpr auto rend(const C& c) noexcept(see-below) -> decltype(c.rend()); // C++14, constexpr since C++17
+template <class E>
+constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il) noexcept; // C++14, constexpr since C++17
+template <class E>
+constexpr reverse_iterator<const E*> rend(initializer_list<E> il) noexcept; // C++14, constexpr since C++17
+template <class T, size_t N>
+constexpr reverse_iterator<T*> rbegin(T (&array)[N]) noexcept; // C++14, constexpr since C++17
+template <class T, size_t N>
+constexpr reverse_iterator<T*> rend(T (&array)[N]) noexcept; // C++14, constexpr since C++17
+template <class C>
+constexpr auto crbegin(const C& c) noexcept(see-below) -> decltype(std::rbegin(c)); // C++14, constexpr since C++17
+template <class C>
+constexpr auto crend(const C& c) noexcept(see-below) -> decltype(std::rend(c)); // C++14, constexpr since C++17
// 24.8, container access:
-template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
-template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
+template <class C> constexpr auto size(const C& c) noexcept(see-below) -> decltype(c.size()); // C++17
+template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
-template <class C> constexpr auto ssize(const C& c)
+template <class C> constexpr auto ssize(const C& c) noexcept(see-below)
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
-template <clas...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/173637
More information about the libcxx-commits
mailing list