Skip to content

Commit e507db3

Browse files
committed
P3016R6 Resolve inconsistencies in begin/end for valarray and braced initializer lists
1 parent a82da99 commit e507db3

File tree

6 files changed

+129
-114
lines changed

6 files changed

+129
-114
lines changed

source/containers.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20532,7 +20532,7 @@
2053220532

2053320533
\pnum
2053420534
\effects
20535-
Initializes \exposid{data_} with \tcode{il.begin()} and
20535+
Initializes \exposid{data_} with \tcode{il.data()} and
2053620536
\exposid{size_} with \tcode{il.size()}.
2053720537
\end{itemdescr}
2053820538

source/iterators.tex

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
\begin{codeblock}
3434
#include <compare> // see \ref{compare.syn}
3535
#include <concepts> // see \ref{concepts.syn}
36+
#include <initializer_list> // see \ref{initializer.list.syn}
3637

3738
namespace std {
3839
template<class T> using @\exposid{with-reference}@ = T&; // \expos
@@ -464,53 +465,64 @@
464465
class ostreambuf_iterator;
465466

466467
// \ref{iterator.range}, range access
467-
template<class C> constexpr auto begin(C& c) -> decltype(c.begin()); // freestanding
468-
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin()); // freestanding
469-
template<class C> constexpr auto end(C& c) -> decltype(c.end()); // freestanding
470-
template<class C> constexpr auto end(const C& c) -> decltype(c.end()); // freestanding
468+
template<class C> constexpr auto
469+
begin(C& c) noexcept(noexcept(c.begin())) -> decltype(c.begin()); // freestanding
470+
template<class C> constexpr auto
471+
begin(const C& c) noexcept(noexcept(c.begin())) -> decltype(c.begin()); // freestanding
472+
template<class C> constexpr auto
473+
end(C& c) noexcept(noexcept(c.end())) -> decltype(c.end()); // freestanding
474+
template<class C> constexpr auto
475+
end(const C& c) noexcept(noexcept(c.end())) -> decltype(c.end()); // freestanding
471476
template<class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept; // freestanding
472477
template<class T, size_t N> constexpr T* end(T (&array)[N]) noexcept; // freestanding
473-
template<class C> constexpr auto cbegin(const C& c) // freestanding
474-
noexcept(noexcept(std::begin(c))) -> decltype(std::begin(c));
475-
template<class C> constexpr auto cend(const C& c) // freestanding
476-
noexcept(noexcept(std::end(c))) -> decltype(std::end(c));
477-
template<class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin()); // freestanding
478-
template<class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); // freestanding
479-
template<class C> constexpr auto rend(C& c) -> decltype(c.rend()); // freestanding
480-
template<class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // freestanding
481-
template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]) // freestanding
482-
template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]); // freestanding
478+
template<class C> constexpr auto
479+
cbegin(const C& c) noexcept(noexcept(std::begin(c)))
480+
-> decltype(std::begin(c)); // freestanding
481+
template<class C> constexpr auto
482+
cend(const C& c) noexcept(noexcept(std::end(c))) -> decltype(std::end(c)); // freestanding
483+
template<class C> constexpr auto
484+
rbegin(C& c) noexcept(noexcept(c.rbegin())) -> decltype(c.rbegin()); // freestanding
485+
template<class C> constexpr auto
486+
rbegin(const C& c) noexcept(noexcept(c.rbegin())) -> decltype(c.rbegin()); // freestanding
487+
template<class C> constexpr auto
488+
rend(C& c) noexcept(noexcept(c.rend())) -> decltype(c.rend()); // freestanding
489+
template<class C> constexpr auto
490+
rend(const C& c) noexcept(noexcept(c.rend())) -> decltype(c.rend()); // freestanding
491+
template<class T, size_t N> constexpr reverse_iterator<T*>
492+
rbegin(T (&array)[N]) noexcept; // freestanding
493+
template<class T, size_t N> constexpr reverse_iterator<T*>
494+
rend(T (&array)[N]) noexcept; // freestanding
483495
template<class E> constexpr reverse_iterator<const E*>
484-
rbegin(initializer_list<E> il); // freestanding
496+
rbegin(initializer_list<E> il) noexcept; // freestanding
485497
template<class E> constexpr reverse_iterator<const E*>
486-
rend(initializer_list<E> il); // freestanding
498+
rend(initializer_list<E> il) noexcept; // freestanding
487499
template<class C> constexpr auto
488-
crbegin(const C& c) -> decltype(std::rbegin(c)); // freestanding
500+
crbegin(const C& c) noexcept(noexcept(std::rbegin(c)))
501+
-> decltype(std::rbegin(c)); // freestanding
489502
template<class C> constexpr auto
490-
crend(const C& c) -> decltype(std::rend(c)); // freestanding
503+
crend(const C& c) noexcept(noexcept(std::rend(c))) -> decltype(std::rend(c)); // freestanding
491504

492505
template<class C> constexpr auto
493-
size(const C& c) -> decltype(c.size()); // freestanding
506+
size(const C& c) noexcept(noexcept(c.size())) -> decltype(c.size()); // freestanding
494507
template<class T, size_t N> constexpr size_t
495508
size(const T (&array)[N]) noexcept; // freestanding
496509

497510
template<class C> constexpr auto
498-
ssize(const C& c)
511+
ssize(const C& c) noexcept(noexcept(c.size()))
499512
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // freestanding
500513
template<class T, ptrdiff_t N> constexpr ptrdiff_t
501514
ssize(const T (&array)[N]) noexcept; // freestanding
502515

503516
template<class C> constexpr auto
504-
empty(const C& c) -> decltype(c.empty()); // freestanding
517+
empty(const C& c) noexcept(noexcept(c.empty())) -> decltype(c.empty()); // freestanding
505518
template<class T, size_t N> constexpr bool
506519
empty(const T (&array)[N]) noexcept; // freestanding
507-
template<class E> constexpr bool
508-
empty(initializer_list<E> il) noexcept; // freestanding
509520

510-
template<class C> constexpr auto data(C& c) -> decltype(c.data()); // freestanding
511-
template<class C> constexpr auto data(const C& c) -> decltype(c.data()); // freestanding
521+
template<class C> constexpr auto
522+
data(C& c) noexcept(noexcept(c.data())) -> decltype(c.data()); // freestanding
523+
template<class C> constexpr auto
524+
data(const C& c) noexcept(noexcept(c.data())) -> decltype(c.data()); // freestanding
512525
template<class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // freestanding
513-
template<class E> constexpr const E* data(initializer_list<E> il) noexcept; // freestanding
514526
}
515527
\end{codeblock}
516528

@@ -7250,19 +7262,24 @@
72507262
\libheaderrefx{inplace_vector}{inplace.vector.syn},
72517263
\libheaderref{list},
72527264
\libheaderrefx{map}{associative.map.syn},
7265+
\libheaderref{optional},
72537266
\libheaderrefx{regex}{re.syn},
72547267
\libheaderrefx{set}{associative.set.syn},
72557268
\libheaderref{span},
7269+
\libheaderref{stacktrace},
72567270
\libheaderref{string},
72577271
\libheaderrefx{string_view}{string.view.synop},
72587272
\libheaderrefx{unordered_map}{unord.map.syn},
7259-
\libheaderrefx{unordered_set}{unord.set.syn}, and
7273+
\libheaderrefx{unordered_set}{unord.set.syn}
7274+
\libheaderref{valarray}, and
72607275
\libheaderref{vector}.
72617276

72627277
\indexlibrary{\idxcode{begin(C\&)}}%
72637278
\begin{itemdecl}
7264-
template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
7265-
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
7279+
template<class C> constexpr auto begin(C& c) noexcept(noexcept(c.begin()))
7280+
-> decltype(c.begin());
7281+
template<class C> constexpr auto begin(const C& c) noexcept(noexcept(c.begin()))
7282+
-> decltype(c.begin());
72667283
\end{itemdecl}
72677284

72687285
\begin{itemdescr}
@@ -7273,8 +7290,8 @@
72737290

72747291
\indexlibrary{\idxcode{end(C\&)}}%
72757292
\begin{itemdecl}
7276-
template<class C> constexpr auto end(C& c) -> decltype(c.end());
7277-
template<class C> constexpr auto end(const C& c) -> decltype(c.end());
7293+
template<class C> constexpr auto end(C& c) noexcept(noexcept(c.end())) -> decltype(c.end());
7294+
template<class C> constexpr auto end(const C& c) noexcept(noexcept(c.end())) -> decltype(c.end());
72787295
\end{itemdecl}
72797296

72807297
\begin{itemdescr}
@@ -7329,8 +7346,10 @@
73297346

73307347
\indexlibrary{\idxcode{rbegin(C\&)}}%
73317348
\begin{itemdecl}
7332-
template<class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin());
7333-
template<class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin());
7349+
template<class C> constexpr auto rbegin(C& c) noexcept(noexcept(c.rbegin()))
7350+
-> decltype(c.rbegin());
7351+
template<class C> constexpr auto rbegin(const C& c) noexcept(noexcept(c.rbegin()))
7352+
-> decltype(c.rbegin());
73347353
\end{itemdecl}
73357354
\begin{itemdescr}
73367355
\pnum
@@ -7340,8 +7359,9 @@
73407359

73417360
\indexlibrary{\idxcode{rend(C\&)}}%
73427361
\begin{itemdecl}
7343-
template<class C> constexpr auto rend(C& c) -> decltype(c.rend());
7344-
template<class C> constexpr auto rend(const C& c) -> decltype(c.rend());
7362+
template<class C> constexpr auto rend(C& c) noexcept(noexcept(c.rend())) -> decltype(c.rend());
7363+
template<class C> constexpr auto rend(const C& c) noexcept(noexcept(c.rend()))
7364+
-> decltype(c.rend());
73457365
\end{itemdecl}
73467366
\begin{itemdescr}
73477367
\pnum
@@ -7351,7 +7371,7 @@
73517371

73527372
\indexlibrary{\idxcode{rbegin(T (\&array)[N])}}%
73537373
\begin{itemdecl}
7354-
template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]);
7374+
template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]) noexcept;
73557375
\end{itemdecl}
73567376
\begin{itemdescr}
73577377
\pnum
@@ -7361,7 +7381,7 @@
73617381

73627382
\indexlibrary{\idxcode{rend(T (\&array)[N])}}%
73637383
\begin{itemdecl}
7364-
template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]);
7384+
template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]) noexcept;
73657385
\end{itemdecl}
73667386
\begin{itemdescr}
73677387
\pnum
@@ -7371,7 +7391,7 @@
73717391

73727392
\indexlibrary{\idxcode{rbegin(initializer_list<E>)}}%
73737393
\begin{itemdecl}
7374-
template<class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il);
7394+
template<class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il) noexcept;
73757395
\end{itemdecl}
73767396
\begin{itemdescr}
73777397
\pnum
@@ -7381,7 +7401,7 @@
73817401

73827402
\indexlibrary{\idxcode{rend(initializer_list<E>)}}%
73837403
\begin{itemdecl}
7384-
template<class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il);
7404+
template<class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il) noexcept;
73857405
\end{itemdecl}
73867406
\begin{itemdescr}
73877407
\pnum
@@ -7391,7 +7411,8 @@
73917411

73927412
\indexlibrary{\idxcode{crbegin(const C\& c)}}%
73937413
\begin{itemdecl}
7394-
template<class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));
7414+
template<class C> constexpr auto crbegin(const C& c) noexcept(noexcept(c.crbegin()))
7415+
-> decltype(std::rbegin(c));
73957416
\end{itemdecl}
73967417
\begin{itemdescr}
73977418
\pnum
@@ -7401,7 +7422,8 @@
74017422

74027423
\indexlibrary{\idxcode{crend(const C\& c)}}%
74037424
\begin{itemdecl}
7404-
template<class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
7425+
template<class C> constexpr auto crend(const C& c) noexcept(noexcept(c.crend()))
7426+
-> decltype(std::rend(c));
74057427
\end{itemdecl}
74067428
\begin{itemdescr}
74077429
\pnum
@@ -7411,7 +7433,8 @@
74117433

74127434
\indexlibrary{\idxcode{size(C\& c)}}%
74137435
\begin{itemdecl}
7414-
template<class C> constexpr auto size(const C& c) -> decltype(c.size());
7436+
template<class C> constexpr auto size(const C& c) noexcept(noexcept(c.size()))
7437+
-> decltype(c.size());
74157438
\end{itemdecl}
74167439
\begin{itemdescr}
74177440
\pnum
@@ -7431,7 +7454,7 @@
74317454

74327455
\indexlibrary{\idxcode{ssize(C\& c)}}%
74337456
\begin{itemdecl}
7434-
template<class C> constexpr auto ssize(const C& c)
7457+
template<class C> constexpr auto ssize(const C& c) noexcept(noexcept(c.ssize()))
74357458
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
74367459
\end{itemdecl}
74377460
\begin{itemdescr}
@@ -7455,7 +7478,8 @@
74557478

74567479
\indexlibrary{\idxcode{empty(C\& c)}}%
74577480
\begin{itemdecl}
7458-
template<class C> constexpr auto empty(const C& c) -> decltype(c.empty());
7481+
template<class C> constexpr auto empty(const C& c) noexcept(noexcept(c.empty()))
7482+
-> decltype(c.empty());
74597483
\end{itemdecl}
74607484
\begin{itemdescr}
74617485
\pnum
@@ -7473,20 +7497,11 @@
74737497
\tcode{false}.
74747498
\end{itemdescr}
74757499

7476-
\indexlibrary{\idxcode{empty(initializer_list<E>)}}%
7477-
\begin{itemdecl}
7478-
template<class E> constexpr bool empty(initializer_list<E> il) noexcept;
7479-
\end{itemdecl}
7480-
\begin{itemdescr}
7481-
\pnum
7482-
\returns
7483-
\tcode{il.size() == 0}.
7484-
\end{itemdescr}
7485-
74867500
\indexlibrary{\idxcode{data(C\& c)}}%
74877501
\begin{itemdecl}
7488-
template<class C> constexpr auto data(C& c) -> decltype(c.data());
7489-
template<class C> constexpr auto data(const C& c) -> decltype(c.data());
7502+
template<class C> constexpr auto data(C& c) noexcept(noexcept(c.data())) -> decltype(c.data());
7503+
template<class C> constexpr auto data(const C& c) noexcept(noexcept(c.data()))
7504+
-> decltype(c.data());
74907505
\end{itemdecl}
74917506
\begin{itemdescr}
74927507
\pnum
@@ -7503,13 +7518,3 @@
75037518
\returns
75047519
\tcode{array}.
75057520
\end{itemdescr}
7506-
7507-
\indexlibrary{\idxcode{data(initializer_list<E>)}}%
7508-
\begin{itemdecl}
7509-
template<class E> constexpr const E* data(initializer_list<E> il) noexcept;
7510-
\end{itemdecl}
7511-
\begin{itemdescr}
7512-
\pnum
7513-
\returns
7514-
\tcode{il.begin()}.
7515-
\end{itemdescr}

0 commit comments

Comments
 (0)