Skip to content

Commit 1bc93f4

Browse files
committed
P2393R1 Cleaning up integer-class types
1 parent 2360a59 commit 1bc93f4

File tree

3 files changed

+113
-69
lines changed

3 files changed

+113
-69
lines changed

source/algorithms.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@
246246
return n;
247247
\end{codeblock}
248248

249+
\pnum
250+
In the description of the algorithms,
251+
given an iterator \tcode{a} whose difference type is \tcode{D}, and
252+
an expression \tcode{n} of integer-like type other than \cv{} \tcode{D},
253+
the semantics of \tcode{a + n} and \tcode{a - n} are, respectively,
254+
those of \tcode{a + D(n)} and \tcode{a - D(n)}.
255+
249256
\pnum
250257
In the description of algorithm return values,
251258
a sentinel value \tcode{s} denoting the end of a range \range{i}{s}

source/iterators.tex

Lines changed: 98 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,35 +1330,85 @@
13301330

13311331
\pnum
13321332
A type \tcode{I} is an \defnadj{integer-class}{type}
1333-
if it is in a set of \impldef{integer-class type} class types
1333+
if it is in a set of \impldef{integer-class type} types
13341334
that behave as integer types do, as defined below.
1335+
\begin{note}
1336+
An integer-class type is not necessarily a class type.
1337+
\end{note}
13351338

13361339
\pnum
13371340
The range of representable values of an integer-class type
13381341
is the continuous set of values over which it is defined.
1339-
The values 0 and 1 are part of the range of every integer-class type.
1340-
If any negative numbers are part of the range,
1341-
the type is a \defnadj{signed-integer-class}{type};
1342-
otherwise, it is an \defnadj{unsigned-integer-class}{type}.
1342+
For any integer-class type,
1343+
its range of representable values is
1344+
either $-2^{N-1}$ to $2^{N-1}-1$ (inclusive) for some integer $N$,
1345+
in which case it is a \defnadj{signed-integer-class}{type}, or
1346+
$0$ to $2^{N-1}$ (inclusive) for some integer $N$,
1347+
in which case it is an \defnadj{unsigned-integer-class}{type}.
1348+
In both cases, $N$ is called the width of the integer-class type.
1349+
The width of an integer-class type is greater than
1350+
that of every integral type of the same signedness.
1351+
1352+
\pnum
1353+
A type \tcode{I} other than \cv{}~\tcode{bool} is \defn{integer-like}
1354+
if it models \tcode{\libconcept{integral}<I>} or
1355+
if it is an integer-class type.
1356+
An integer-like type \tcode{I} is \defn{signed-integer-like}
1357+
if it models \tcode{\libconcept{signed_integral}<I>} or
1358+
if it is a signed-integer-class type.
1359+
An integer-like type \tcode{I} is \defn{unsigned-integer-like}
1360+
if it models \tcode{\libconcept{unsigned_integral}<I>} or
1361+
if it is an unsigned-integer-class type.
13431362

13441363
\pnum
13451364
For every integer-class type \tcode{I},
1346-
let \tcode{B(I)} be a hypothetical extended integer type
1347-
of the same signedness with the smallest width\iref{basic.fundamental}
1348-
capable of representing the same range of values.
1349-
The width of \tcode{I} is equal to the width of \tcode{B(I)}.
1365+
let \tcode{B(I)} be a unique hypothetical extended integer type
1366+
of the same signedness with the same width\iref{basic.fundamental} as \tcode{I}.
1367+
\begin{note}
1368+
The corresponding hypothetical specialization \tcode{numeric_limits<B(I)>}
1369+
meets the requirements on \tcode{numeric_limits} specializations
1370+
for integral types\iref{numeric.limits}.
1371+
\end{note}
1372+
For every integral type \tcode{J}, let B(J)c be the same type as \tcode{J}.
13501373

13511374
\pnum
1352-
Let \tcode{a} and \tcode{b} be objects of integer-class type \tcode{I},
1353-
let \tcode{x} and \tcode{y} be objects of type \tcode{B(I)} as described above
1354-
that represent the same values as \tcode{a} and \tcode{b} respectively, and
1375+
Expressions of integer-class type are
1376+
explicitly convertible to any integer-like type, and
1377+
implicitly convertible to any integer-class type
1378+
of equal or greater width and the same signedness.
1379+
Expressions of integral type are
1380+
both implicitly and explicitly convertible to any integer-class type.
1381+
Conversions between integral and integer-class types
1382+
and between two integer-class types do not exit via an exception.
1383+
The result of such a conversion is the unique value of the destination type
1384+
that is congruent to the source modulo $2^N$,
1385+
where $N$ is the width of the destination type.
1386+
1387+
\pnum
1388+
Let \tcode{a} be an object of integer-class type \tcode{I},
1389+
let \tcode{b} be an object of integer-like type \tcode{I2}
1390+
such that the expression \tcode{b} is implicitly convertible to \tcode{I},
1391+
let \tcode{x} and \tcode{y} be, respectively,
1392+
objects of type \tcode{B(I)} and \tcode{B(I2)} as described above
1393+
that represent the same values as \tcode{a} and \tcode{b}, and
13551394
let \tcode{c} be an lvalue of any integral type.
13561395
\begin{itemize}
13571396
\item
1358-
For every unary operator \tcode{@} for which the expression \tcode{@x}
1397+
The expressions \tcode{a++} and \tcode{a--} shall be prvalues of type \tcode{I}
1398+
whose values are equal to
1399+
that of \tcode{a} prior to the evaluation of the expressions.
1400+
The expression \tcode{a++} shall modify the value of \tcode{a}
1401+
by adding 1 to it.
1402+
The expression \tcode{a--} shall modify the value of \tcode{a}
1403+
by subtracting 1 from it.
1404+
\item
1405+
The expressions \tcode{++a}, \tcode{--a}, and \tcode{\&a} shall be
1406+
expression-equivalent to
1407+
\tcode{a += 1}, \tcode{a -= 1}, and \tcode{addressof(a)}, respectively.
1408+
\item
1409+
For every \grammarterm{unary-operator} \tcode{@} other than \tcode{\&} for which the expression \tcode{@x}
13591410
is well-formed, \tcode{@a} shall also be well-formed
1360-
and have the same value, effects, and value category as \tcode{@x}
1361-
provided that value is representable by \tcode{I}.
1411+
and have the same value, effects, and value category as \tcode{@x}.
13621412
If \tcode{@x} has type \tcode{bool}, so too does \tcode{@a};
13631413
if \tcode{@x} has type \tcode{B(I)}, then \tcode{@a} has type \tcode{I}.
13641414
\item
@@ -1368,22 +1418,27 @@
13681418
shall have the same value and effects as \tcode{c @= x}.
13691419
The expression \tcode{c @= a} shall be an lvalue referring to \tcode{c}.
13701420
\item
1371-
For every binary operator \tcode{@} for which \tcode{x @ y} is well-formed,
1372-
\tcode{a @ b} shall also be well-formed and
1373-
shall have the same value, effects, and value category as \tcode{x @ y}
1374-
provided that value is representable by \tcode{I}.
1375-
If \tcode{x @ y} has type \tcode{bool}, so too does \tcode{a @ b};
1376-
if \tcode{x @ y} has type \tcode{B(I)}, then \tcode{a @ b} has type \tcode{I}.
1421+
For every assignment operator \tcode{@=}
1422+
for which \tcode{x @= y} is well-formed,
1423+
\tcode{a @= b} shall also be well-formed and
1424+
shall have the same effects as \tcode{x @= y},
1425+
except that the value that would be stored into \tcode{x}
1426+
is stored into \tcode{a}.
1427+
The expression \tcode{a @= b} shall be an lvalue referring to \tcode{a}.
1428+
\item
1429+
For every non-assignment binary operator \tcode{@}
1430+
for which \tcode{x @ y} and \tcode{y @ x} are well-formed,
1431+
\tcode{a @ b} and \tcode{b @ a} shall also be well-formed and
1432+
shall have the same value, effects, and value category as
1433+
\tcode{x @ y} and \tcode{y @ x}, respectively.
1434+
If \tcode{x @ y} or \tcode{y @ x} has type \tcode{B(I)},
1435+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has type \tcode{I};
1436+
if \tcode{x @ y} or \tcode{y @ x} has type \tcode{B(I2)},
1437+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has type \tcode{I2};
1438+
if \tcode{x @ y} or \tcode{y @ x} has any other type,
1439+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has that type.
13771440
\end{itemize}
13781441

1379-
\pnum
1380-
Expressions of integer-class type are
1381-
explicitly convertible to any integral type.
1382-
Expressions of integral type are
1383-
both implicitly and explicitly convertible to any integer-class type.
1384-
Conversions between integral and integer-class types
1385-
do not exit via an exception.
1386-
13871442
\pnum
13881443
An expression \tcode{E} of integer-class type \tcode{I} is
13891444
contextually convertible to \tcode{bool}
@@ -1392,44 +1447,26 @@
13921447
\pnum
13931448
All integer-class types model
13941449
\libconcept{regular}\iref{concepts.object} and
1395-
\libconcept{totally_ordered}\iref{concept.totallyordered}.
1450+
\libconcept{three_way_comparable}<strong_ordering>\iref{cmp.concept}.
13961451

13971452
\pnum
13981453
A value-initialized object of integer-class type has value 0.
13991454

14001455
\pnum
14011456
For every (possibly cv-qualified) integer-class type \tcode{I},
1402-
\tcode{numeric_limits<I>} is specialized such that:
1403-
\begin{itemize}
1404-
\item
1405-
\tcode{numeric_limits<I>::is_specialized} is \tcode{true},
1406-
\item
1407-
\tcode{numeric_limits<I>::is_signed} is \tcode{true}
1408-
if and only if \tcode{I} is a signed-integer-class type,
1409-
\item
1410-
\tcode{numeric_limits<I>::is_integer} is \tcode{true},
1411-
\item
1412-
\tcode{numeric_limits<I>::is_exact} is \tcode{true},
1413-
\item
1414-
\tcode{numeric_limits<I>::digits} is equal to the width of the integer-class type,
1415-
\item
1416-
\tcode{numeric_limits<I>::digits10} is equal to \tcode{static_cast<int>(digits * log10(2))}, and
1417-
\item
1418-
\tcode{numeric_limits<I>::min()} and \tcode{numeric_limits<I>::max()} return
1419-
the lowest and highest representable values of \tcode{I}, respectively, and
1420-
\tcode{numeric_limits<I>::lowest()} returns \tcode{numeric_limits<I>::\brk{}min()}.
1421-
\end{itemize}
1422-
1423-
\pnum
1424-
A type \tcode{I} other than \cv{}~\tcode{bool} is \defn{integer-like}
1425-
if it models \tcode{\libconcept{integral}<I>} or
1426-
if it is an integer-class type.
1427-
An integer-like type \tcode{I} is \defn{signed-integer-like}
1428-
if it models \tcode{\libconcept{signed_integral}<I>} or
1429-
if it is a signed-integer-class type.
1430-
An integer-like type \tcode{I} is \defn{unsigned-integer-like}
1431-
if it models \tcode{\libconcept{unsigned_integral}<I>} or
1432-
if it is an unsigned-integer-class type.
1457+
\tcode{numeric_limits<I>} is specialized such that
1458+
each static data member \tcode{m}
1459+
has the same value as \tcode{numeric_limits<B(I)>::m}, and
1460+
each static member function \tcode{f}
1461+
returns \tcode{I(numeric_limits<B(I)>::f())}.
1462+
1463+
\pnum
1464+
For any two integer-like types \tcode{I1} and \tcode{I2},
1465+
at least one of which is an integer-class type,
1466+
\tcode{common_type_t<I1, I2>} denotes an integer-class type
1467+
whose width is not less than that of \tcode{I1} or \tcode{I2}.
1468+
If both \tcode{I1} and \tcode{I2} are signed-integer-like types,
1469+
then \tcode{common_type_t<I1, I2>} is also a signed-integer-like type.
14331470

14341471
\pnum
14351472
\tcode{\exposid{is-integer-like}<I>} is \tcode{true}

source/ranges.tex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@
16691669
Equivalent to:
16701670
\begin{itemize}
16711671
\item If \exposid{StoreSize} is \tcode{true},
1672-
\tcode{subrange(r, ranges::size(r))}.
1672+
\tcode{subrange(r, static_cast<decltype(\exposid{size_}-)>(ranges::size(r)))}.
16731673
\item Otherwise, \tcode{subrange(ranges::begin(r), ranges::end(r))}.
16741674
\end{itemize}
16751675
\end{itemdescr}
@@ -4484,7 +4484,7 @@
44844484
\item a specialization of \tcode{ranges::iota_view}\iref{range.iota.view}, or
44854485
\item a specialization of \tcode{ranges::subrange}\iref{range.subrange},
44864486
\end{itemize}
4487-
then \tcode{T(ranges::begin(E), ranges::begin(E) + min<D>(ranges::size(E), F))},
4487+
then \tcode{T(ranges::begin(E), ranges::begin(E) + std::min<D>(ranges::distance(E), F))},\newline
44884488
except that \tcode{E} is evaluated only once.
44894489

44904490
\item
@@ -4528,7 +4528,7 @@
45284528
if constexpr (@\libconcept{random_access_range}@<V>)
45294529
return ranges::begin(@\exposid{base_}@);
45304530
else {
4531-
auto sz = size();
4531+
auto sz = range_difference_t<V>(size());
45324532
return counted_iterator(ranges::begin(@\exposid{base_}@), sz);
45334533
}
45344534
} else
@@ -4540,7 +4540,7 @@
45404540
if constexpr (@\libconcept{random_access_range}@<const V>)
45414541
return ranges::begin(@\exposid{base_}@);
45424542
else {
4543-
auto sz = size();
4543+
auto sz = range_difference_t<V>(size());
45444544
return counted_iterator(ranges::begin(@\exposid{base_}@), sz);
45454545
}
45464546
} else
@@ -4550,7 +4550,7 @@
45504550
constexpr auto end() requires (!@\exposconcept{simple-view}@<V>) {
45514551
if constexpr (@\libconcept{sized_range}@<V>) {
45524552
if constexpr (@\libconcept{random_access_range}@<V>)
4553-
return ranges::begin(@\exposid{base_}@) + size();
4553+
return ranges::begin(@\exposid{base_}@) + range_difference_t<V>(size());
45544554
else
45554555
return default_sentinel;
45564556
} else
@@ -4560,7 +4560,7 @@
45604560
constexpr auto end() const requires @\libconcept{range}@<const V> {
45614561
if constexpr (@\libconcept{sized_range}@<const V>) {
45624562
if constexpr (@\libconcept{random_access_range}@<const V>)
4563-
return ranges::begin(@\exposid{base_}@) + size();
4563+
return ranges::begin(@\exposid{base_}@) + range_difference_t<V>(size());
45644564
else
45654565
return default_sentinel;
45664566
} else
@@ -4895,7 +4895,7 @@
48954895
\item a specialization of \tcode{ranges::iota_view}\iref{range.iota.view}, or
48964896
\item a specialization of \tcode{ranges::subrange}\iref{range.subrange},
48974897
\end{itemize}
4898-
then \tcode{T(ranges::begin(E) + min<D>(ranges::size(E), F), ranges::end(E))},
4898+
then \tcode{T(ranges::begin(E) + std::min<D>(ranges::distance(E), F), ranges::end(E))},
48994899
except that \tcode{E} is evaluated only once.
49004900

49014901
\item
@@ -6502,7 +6502,7 @@
65026502
\begin{itemize}
65036503
\item
65046504
If \tcode{T} models \libconcept{contiguous_iterator},
6505-
then \tcode{span(to_address(E), static_cast<D>(F))}.
6505+
then \tcode{span(to_address(E), static_cast<size_t>(static_-\linebreak{}cast<D>(F)))}.
65066506

65076507
\item
65086508
Otherwise, if \tcode{T} models \libconcept{random_access_iterator},

0 commit comments

Comments
 (0)