Skip to content

Commit ebbb963

Browse files
jensmaurertkoeppe
authored andcommitted
P2393R1 Cleaning up integer-class types
1 parent 8f900e1 commit ebbb963

File tree

3 files changed

+112
-67
lines changed

3 files changed

+112
-67
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: 99 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,35 +1333,86 @@
13331333

13341334
\pnum
13351335
A type \tcode{I} is an \defnadj{integer-class}{type}
1336-
if it is in a set of \impldef{integer-class type} class types
1336+
if it is in a set of \impldef{integer-class type} types
13371337
that behave as integer types do, as defined below.
1338+
\begin{note}
1339+
An integer-class type is not necessarily a class type.
1340+
\end{note}
13381341

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

13471367
\pnum
13481368
For every integer-class type \tcode{I},
1349-
let \tcode{B(I)} be a hypothetical extended integer type
1350-
of the same signedness with the smallest width\iref{basic.fundamental}
1351-
capable of representing the same range of values.
1352-
The width of \tcode{I} is equal to the width of \tcode{B(I)}.
1369+
let \tcode{B(I)} be a unique hypothetical extended integer type
1370+
of the same signedness with the same width\iref{basic.fundamental} as \tcode{I}.
1371+
\begin{note}
1372+
The corresponding hypothetical specialization \tcode{numeric_limits<B(I)>}
1373+
meets the requirements on \tcode{numeric_limits} specializations
1374+
for integral types\iref{numeric.limits}.
1375+
\end{note}
1376+
For every integral type \tcode{J}, let \tcode{B(J)} be the same type as \tcode{J}.
13531377

13541378
\pnum
1355-
Let \tcode{a} and \tcode{b} be objects of integer-class type \tcode{I},
1356-
let \tcode{x} and \tcode{y} be objects of type \tcode{B(I)} as described above
1357-
that represent the same values as \tcode{a} and \tcode{b} respectively, and
1379+
Expressions of integer-class type are
1380+
explicitly convertible to any integer-like type, and
1381+
implicitly convertible to any integer-class type
1382+
of equal or greater width and the same signedness.
1383+
Expressions of integral type are
1384+
both implicitly and explicitly convertible to any integer-class type.
1385+
Conversions between integral and integer-class types
1386+
and between two integer-class types do not exit via an exception.
1387+
The result of such a conversion is the unique value of the destination type
1388+
that is congruent to the source modulo $2^N$,
1389+
where $N$ is the width of the destination type.
1390+
1391+
\pnum
1392+
Let \tcode{a} be an object of integer-class type \tcode{I},
1393+
let \tcode{b} be an object of integer-like type \tcode{I2}
1394+
such that the expression \tcode{b} is implicitly convertible to \tcode{I},
1395+
let \tcode{x} and \tcode{y} be, respectively,
1396+
objects of type \tcode{B(I)} and \tcode{B(I2)} as described above
1397+
that represent the same values as \tcode{a} and \tcode{b}, and
13581398
let \tcode{c} be an lvalue of any integral type.
13591399
\begin{itemize}
13601400
\item
1361-
For every unary operator \tcode{@} for which the expression \tcode{@x}
1401+
The expressions \tcode{a++} and \tcode{a--} shall be prvalues of type \tcode{I}
1402+
whose values are equal to
1403+
that of \tcode{a} prior to the evaluation of the expressions.
1404+
The expression \tcode{a++} shall modify the value of \tcode{a}
1405+
by adding \tcode{1} to it.
1406+
The expression \tcode{a--} shall modify the value of \tcode{a}
1407+
by subtracting \tcode{1} from it.
1408+
\item
1409+
The expressions \tcode{++a}, \tcode{--a}, and \tcode{\&a} shall be
1410+
expression-equivalent to
1411+
\tcode{a += 1}, \tcode{a -= 1}, and \tcode{addressof(a)}, respectively.
1412+
\item
1413+
For every \grammarterm{unary-operator} \tcode{@} other than \tcode{\&} for which the expression \tcode{@x}
13621414
is well-formed, \tcode{@a} shall also be well-formed
1363-
and have the same value, effects, and value category as \tcode{@x}
1364-
provided that value is representable by \tcode{I}.
1415+
and have the same value, effects, and value category as \tcode{@x}.
13651416
If \tcode{@x} has type \tcode{bool}, so too does \tcode{@a};
13661417
if \tcode{@x} has type \tcode{B(I)}, then \tcode{@a} has type \tcode{I}.
13671418
\item
@@ -1371,22 +1422,27 @@
13711422
shall have the same value and effects as \tcode{c @= x}.
13721423
The expression \tcode{c @= a} shall be an lvalue referring to \tcode{c}.
13731424
\item
1374-
For every binary operator \tcode{@} for which \tcode{x @ y} is well-formed,
1375-
\tcode{a @ b} shall also be well-formed and
1376-
shall have the same value, effects, and value category as \tcode{x @ y}
1377-
provided that value is representable by \tcode{I}.
1378-
If \tcode{x @ y} has type \tcode{bool}, so too does \tcode{a @ b};
1379-
if \tcode{x @ y} has type \tcode{B(I)}, then \tcode{a @ b} has type \tcode{I}.
1425+
For every assignment operator \tcode{@=}
1426+
for which \tcode{x @= y} is well-formed,
1427+
\tcode{a @= b} shall also be well-formed and
1428+
shall have the same effects as \tcode{x @= y},
1429+
except that the value that would be stored into \tcode{x}
1430+
is stored into \tcode{a}.
1431+
The expression \tcode{a @= b} shall be an lvalue referring to \tcode{a}.
1432+
\item
1433+
For every non-assignment binary operator \tcode{@}
1434+
for which \tcode{x @ y} and \tcode{y @ x} are well-formed,
1435+
\tcode{a @ b} and \tcode{b @ a} shall also be well-formed and
1436+
shall have the same value, effects, and value category as
1437+
\tcode{x @ y} and \tcode{y @ x}, respectively.
1438+
If \tcode{x @ y} or \tcode{y @ x} has type \tcode{B(I)},
1439+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has type \tcode{I};
1440+
if \tcode{x @ y} or \tcode{y @ x} has type \tcode{B(I2)},
1441+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has type \tcode{I2};
1442+
if \tcode{x @ y} or \tcode{y @ x} has any other type,
1443+
then \tcode{a @ b} or \tcode{b @ a}, respectively, has that type.
13801444
\end{itemize}
13811445

1382-
\pnum
1383-
Expressions of integer-class type are
1384-
explicitly convertible to any integral type.
1385-
Expressions of integral type are
1386-
both implicitly and explicitly convertible to any integer-class type.
1387-
Conversions between integral and integer-class types
1388-
do not exit via an exception.
1389-
13901446
\pnum
13911447
An expression \tcode{E} of integer-class type \tcode{I} is
13921448
contextually convertible to \tcode{bool}
@@ -1395,44 +1451,26 @@
13951451
\pnum
13961452
All integer-class types model
13971453
\libconcept{regular}\iref{concepts.object} and
1398-
\libconcept{totally_ordered}\iref{concept.totallyordered}.
1454+
\tcode{\libconcept{three_way_comparable}<strong_ordering>}\iref{cmp.concept}.
13991455

14001456
\pnum
14011457
A value-initialized object of integer-class type has value 0.
14021458

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

14371475
\pnum
14381476
\tcode{\exposid{is-integer-like}<I>} is \tcode{true}

source/ranges.tex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@
17081708
Equivalent to:
17091709
\begin{itemize}
17101710
\item If \exposid{StoreSize} is \tcode{true},
1711-
\tcode{subrange(r, ranges::size(r))}.
1711+
\tcode{subrange(r, static_cast<decltype(\exposid{size_})>(ranges::size(r)))}.
17121712
\item Otherwise, \tcode{subrange(ranges::begin(r), ranges::end(r))}.
17131713
\end{itemize}
17141714
\end{itemdescr}
@@ -4654,7 +4654,7 @@
46544654
if constexpr (@\libconcept{random_access_range}@<V>)
46554655
return ranges::begin(@\exposid{base_}@);
46564656
else {
4657-
auto sz = size();
4657+
auto sz = range_difference_t<V>(size());
46584658
return counted_iterator(ranges::begin(@\exposid{base_}@), sz);
46594659
}
46604660
} else
@@ -4666,7 +4666,7 @@
46664666
if constexpr (@\libconcept{random_access_range}@<const V>)
46674667
return ranges::begin(@\exposid{base_}@);
46684668
else {
4669-
auto sz = size();
4669+
auto sz = range_difference_t<V>(size());
46704670
return counted_iterator(ranges::begin(@\exposid{base_}@), sz);
46714671
}
46724672
} else
@@ -4676,7 +4676,7 @@
46764676
constexpr auto end() requires (!@\exposconcept{simple-view}@<V>) {
46774677
if constexpr (@\libconcept{sized_range}@<V>) {
46784678
if constexpr (@\libconcept{random_access_range}@<V>)
4679-
return ranges::begin(@\exposid{base_}@) + size();
4679+
return ranges::begin(@\exposid{base_}@) + range_difference_t<V>(size());
46804680
else
46814681
return default_sentinel;
46824682
} else
@@ -4686,7 +4686,7 @@
46864686
constexpr auto end() const requires @\libconcept{range}@<const V> {
46874687
if constexpr (@\libconcept{sized_range}@<const V>) {
46884688
if constexpr (@\libconcept{random_access_range}@<const V>)
4689-
return ranges::begin(@\exposid{base_}@) + size();
4689+
return ranges::begin(@\exposid{base_}@) + range_difference_t<V>(size());
46904690
else
46914691
return default_sentinel;
46924692
} else
@@ -6646,7 +6646,7 @@
66466646
\begin{itemize}
66476647
\item
66486648
If \tcode{T} models \libconcept{contiguous_iterator},
6649-
then \tcode{span(to_address(E), static_cast<D>(F))}.
6649+
then \tcode{span(to_address(E), static_cast<size_t>(static_-\linebreak{}cast<D>(F)))}.
66506650

66516651
\item
66526652
Otherwise, if \tcode{T} models \libconcept{random_access_iterator},

0 commit comments

Comments
 (0)