|
589 | 589 | \end{itemize}
|
590 | 590 |
|
591 | 591 | \item
|
592 |
| - Otherwise, \tcode{(ranges::end(E) - ranges::begin(E))} |
| 592 | + Otherwise, \tcode{\placeholdernc{make-unsigned-like}(ranges::end(E) - ranges::begin(E))}\iref{range.subrange} |
593 | 593 | if it is a valid expression and
|
594 | 594 | the types \tcode{I} and \tcode{S} of \tcode{ranges::begin(E)} and
|
595 |
| - \tcode{ranges::end(E)} (respectively) model both |
| 595 | + \tcode{ranges::end(E)} (respectively) model both\hfill\break %avoid overfull |
596 | 596 | \tcode{SizedSentinel<S, I>}\iref{iterator.concept.sizedsentinel} and
|
597 | 597 | \tcode{Forward\-Iterator<I>}.
|
598 | 598 | However, \tcode{E} is evaluated only once.
|
|
1209 | 1209 | \begin{codeblock}
|
1210 | 1210 | namespace std::ranges {
|
1211 | 1211 | template<class T>
|
1212 |
| - concept @\placeholdernc{pair-like}@ = // \expos |
| 1212 | + concept @\placeholdernc{pair-like}@ = // \expos |
1213 | 1213 | !is_reference_v<T> && requires(T t) {
|
1214 | 1214 | typename tuple_size<T>::type; // ensures \tcode{tuple_size<T>} is complete
|
1215 | 1215 | requires DerivedFrom<tuple_size<T>, integral_constant<size_t, 2>>;
|
|
1220 | 1220 | };
|
1221 | 1221 |
|
1222 | 1222 | template<class T, class U, class V>
|
1223 |
| - concept @\placeholdernc{pair-like-convertible-to}@ = // \expos |
| 1223 | + concept @\placeholdernc{pair-like-convertible-to}@ = // \expos |
1224 | 1224 | !Range<T> && @\placeholder{pair-like}@<remove_reference_t<T>> &&
|
1225 | 1225 | requires(T&& t) {
|
1226 | 1226 | { get<0>(std::forward<T>(t)) } -> ConvertibleTo<U>;
|
1227 | 1227 | { get<1>(std::forward<T>(t)) } -> ConvertibleTo<V>;
|
1228 | 1228 | };
|
1229 | 1229 |
|
1230 | 1230 | template<class T, class U, class V>
|
1231 |
| - concept @\placeholdernc{pair-like-convertible-from}@ = // \expos |
| 1231 | + concept @\placeholdernc{pair-like-convertible-from}@ = // \expos |
1232 | 1232 | !Range<T> && @\placeholdernc{pair-like}@<T> && Constructible<T, U, V>;
|
1233 | 1233 |
|
1234 | 1234 | template<class T>
|
1235 |
| - concept @\placeholdernc{iterator-sentinel-pair}@ = // \expos |
| 1235 | + concept @\placeholdernc{iterator-sentinel-pair}@ = // \expos |
1236 | 1236 | !Range<T> && @\placeholdernc{pair-like}@<T> &&
|
1237 | 1237 | Sentinel<tuple_element_t<1, T>, tuple_element_t<0, T>>;
|
1238 | 1238 |
|
|
1241 | 1241 | requires (K == subrange_kind::sized || !SizedSentinel<S, I>)
|
1242 | 1242 | class subrange : public view_interface<subrange<I, S, K>> {
|
1243 | 1243 | private:
|
1244 |
| - static constexpr bool StoreSize = // \expos |
| 1244 | + static constexpr bool StoreSize = // \expos |
1245 | 1245 | K == subrange_kind::sized && !SizedSentinel<S, I>;
|
1246 |
| - I begin_ = I(); // \expos |
1247 |
| - S end_ = S(); // \expos |
1248 |
| - iter_difference_t<I> size_ = 0; // \expos; present only |
1249 |
| - // when \tcode{StoreSize} is \tcode{true} |
| 1246 | + I begin_ = I(); // \expos |
| 1247 | + S end_ = S(); // \expos |
| 1248 | + @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) size_ = 0; // \expos; present only |
| 1249 | + // when \tcode{StoreSize} is \tcode{true} |
1250 | 1250 | public:
|
1251 | 1251 | subrange() = default;
|
1252 | 1252 |
|
1253 | 1253 | constexpr subrange(I i, S s) requires (!StoreSize);
|
1254 | 1254 |
|
1255 |
| - constexpr subrange(I i, S s, iter_difference_t<I> n) |
| 1255 | + constexpr subrange(I i, S s, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) n) |
1256 | 1256 | requires (K == subrange_kind::sized);
|
1257 | 1257 |
|
1258 | 1258 | template<@\placeholdernc{not-same-as}@<subrange> R>
|
|
1262 | 1262 |
|
1263 | 1263 | template<@\placeholdernc{forwarding-range}@ R>
|
1264 | 1264 | requires ConvertibleTo<iterator_t<R>, I> && ConvertibleTo<sentinel_t<R>, S>
|
1265 |
| - constexpr subrange(R&& r, iter_difference_t<I> n) |
| 1265 | + constexpr subrange(R&& r, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) n) |
1266 | 1266 | requires (K == subrange_kind::sized)
|
1267 | 1267 | : subrange{ranges::begin(r), ranges::end(r), n}
|
1268 | 1268 | {}
|
|
1275 | 1275 | {}
|
1276 | 1276 |
|
1277 | 1277 | template<@\placeholdernc{pair-like-convertible-to}@<I, S> PairLike>
|
1278 |
| - constexpr subrange(PairLike&& r, iter_difference_t<I> n) |
| 1278 | + constexpr subrange(PairLike&& r, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) n) |
1279 | 1279 | requires (K == subrange_kind::sized)
|
1280 | 1280 | : subrange{std::get<0>(std::forward<PairLike>(r)),
|
1281 | 1281 | std::get<1>(std::forward<PairLike>(r)), n}
|
|
1289 | 1289 | constexpr S end() const;
|
1290 | 1290 |
|
1291 | 1291 | constexpr bool empty() const;
|
1292 |
| - constexpr iter_difference_t<I> size() const |
| 1292 | + constexpr @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) size() const |
1293 | 1293 | requires (K == subrange_kind::sized);
|
1294 | 1294 |
|
1295 | 1295 | [[nodiscard]] constexpr subrange next(iter_difference_t<I> n = 1) const;
|
|
1302 | 1302 | };
|
1303 | 1303 |
|
1304 | 1304 | template<Iterator I, Sentinel<I> S>
|
1305 |
| - subrange(I, S, iter_difference_t<I>) -> subrange<I, S, subrange_kind::sized>; |
| 1305 | + subrange(I, S, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>)) -> |
| 1306 | + subrange<I, S, subrange_kind::sized>; |
1306 | 1307 |
|
1307 | 1308 | template<@\placeholder{iterator-sentinel-pair}@ P>
|
1308 | 1309 | subrange(P) -> subrange<tuple_element_t<0, P>, tuple_element_t<1, P>>;
|
1309 | 1310 |
|
1310 | 1311 | template<@\placeholder{iterator-sentinel-pair}@ P>
|
1311 |
| - subrange(P, iter_difference_t<tuple_element_t<0, P>>) -> |
| 1312 | + subrange(P, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<tuple_element_t<0, P>>)) -> |
1312 | 1313 | subrange<tuple_element_t<0, P>, tuple_element_t<1, P>, subrange_kind::sized>;
|
1313 | 1314 |
|
1314 | 1315 | template<@\placeholder{forwarding-range}@ R>
|
|
1318 | 1319 | ? subrange_kind::sized : subrange_kind::unsized>;
|
1319 | 1320 |
|
1320 | 1321 | template<@\placeholder{forwarding-range}@ R>
|
1321 |
| - subrange(R&&, range_difference_t<R>) -> |
| 1322 | + subrange(R&&, @\placeholdernc{make-unsigned-like-t}@(range_difference_t<R>)) -> |
1322 | 1323 | subrange<iterator_t<R>, sentinel_t<R>, subrange_kind::sized>;
|
1323 | 1324 |
|
1324 | 1325 | template<size_t N, class I, class S, subrange_kind K>
|
|
1349 | 1350 |
|
1350 | 1351 | \indexlibrary{\idxcode{subrange}!\idxcode{subrange}}%
|
1351 | 1352 | \begin{itemdecl}
|
1352 |
| -constexpr subrange(I i, S s, iter_difference_t<I> n) |
| 1353 | +constexpr subrange(I i, S s, @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) n) |
1353 | 1354 | requires (K == subrange_kind::sized);
|
1354 | 1355 | \end{itemdecl}
|
1355 | 1356 |
|
1356 | 1357 | \begin{itemdescr}
|
1357 | 1358 | \pnum
|
1358 | 1359 | \expects \range{i}{s} is a valid range, and
|
1359 |
| -\tcode{n == ranges::distance(i, s)}. |
| 1360 | +\tcode{n == \placeholdernc{make-unsigned-like}(ranges::distance(i, s))}. |
1360 | 1361 |
|
1361 | 1362 | \pnum
|
1362 | 1363 | \effects Initializes \tcode{begin_} with \tcode{i} and \tcode{end_} with
|
|
1436 | 1437 |
|
1437 | 1438 | \indexlibrary{\idxcode{size}!\idxcode{subrange}}%
|
1438 | 1439 | \begin{itemdecl}
|
1439 |
| -constexpr iter_difference_t<I> size() const |
| 1440 | +constexpr @\placeholdernc{make-unsigned-like-t}@(iter_difference_t<I>) size() const |
1440 | 1441 | requires (K == subrange_kind::sized);
|
1441 | 1442 | \end{itemdecl}
|
1442 | 1443 |
|
|
1445 | 1446 | \effects
|
1446 | 1447 | \begin{itemize}
|
1447 | 1448 | \item If \tcode{StoreSize} is \tcode{true}, equivalent to: \tcode{return size_;}
|
1448 |
| -\item Otherwise, equivalent to: \tcode{return end_ - begin_;} |
| 1449 | +\item Otherwise, equivalent to: \tcode{return \placeholdernc{make-unsigned-like-t}(end_ - begin_);} |
1449 | 1450 | \end{itemize}
|
1450 | 1451 | \end{itemdescr}
|
1451 | 1452 |
|
|
1497 | 1498 | \begin{itemize}
|
1498 | 1499 | \item If \tcode{StoreSize} is \tcode{true},
|
1499 | 1500 | \begin{codeblock}
|
1500 |
| -size_ -= n - ranges::advance(begin_, n, end_); |
| 1501 | +auto d = n - ranges::advance(begin_, n, end_); |
| 1502 | +if (d >= 0) |
| 1503 | + size_ -= @\placeholdernc{make-unsigned-like}@(d); |
| 1504 | +else |
| 1505 | + size_ += @\placeholdernc{make-unsigned-like}@(-d); |
1501 | 1506 | return *this;
|
1502 | 1507 | \end{codeblock}
|
1503 | 1508 | \item Otherwise,
|
|
1605 | 1610 | static constexpr T* begin() noexcept { return nullptr; }
|
1606 | 1611 | static constexpr T* end() noexcept { return nullptr; }
|
1607 | 1612 | static constexpr T* data() noexcept { return nullptr; }
|
1608 |
| - static constexpr ptrdiff_t size() noexcept { return 0; } |
| 1613 | + static constexpr size_t size() noexcept { return 0; } |
1609 | 1614 | static constexpr bool empty() noexcept { return true; }
|
1610 | 1615 |
|
1611 | 1616 | friend constexpr T* begin(empty_view) noexcept { return nullptr; }
|
|
1652 | 1657 | constexpr const T* begin() const noexcept;
|
1653 | 1658 | constexpr T* end() noexcept;
|
1654 | 1659 | constexpr const T* end() const noexcept;
|
1655 |
| - static constexpr ptrdiff_t size() noexcept; |
| 1660 | + static constexpr size_t size() noexcept; |
1656 | 1661 | constexpr T* data() noexcept;
|
1657 | 1662 | constexpr const T* data() const noexcept;
|
1658 | 1663 | };
|
|
1715 | 1720 |
|
1716 | 1721 | \indexlibrary{\idxcode{size}!\idxcode{single_view}}%
|
1717 | 1722 | \begin{itemdecl}
|
1718 |
| -static constexpr ptrdiff_t size() noexcept; |
| 1723 | +static constexpr size_t size() noexcept; |
1719 | 1724 | \end{itemdecl}
|
1720 | 1725 |
|
1721 | 1726 | \begin{itemdescr}
|
|
0 commit comments