[libcxx-commits] [libcxx] fbaf7f0 - [libc++] Add range_size_t
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 26 09:19:31 PDT 2021
Author: Louis Dionne
Date: 2021-07-26T12:19:26-04:00
New Revision: fbaf7f0bc768bb236db49a2fea79169f91c10720
URL: https://github.com/llvm/llvm-project/commit/fbaf7f0bc768bb236db49a2fea79169f91c10720
DIFF: https://github.com/llvm/llvm-project/commit/fbaf7f0bc768bb236db49a2fea79169f91c10720.diff
LOG: [libc++] Add range_size_t
Differential Revision: https://reviews.llvm.org/D106708
Added:
libcxx/test/std/ranges/range.req/range.range/range_size_t.compile.pass.cpp
Modified:
libcxx/docs/Status/RangesPaper.csv
libcxx/include/__ranges/concepts.h
libcxx/include/ranges
Removed:
################################################################################
diff --git a/libcxx/docs/Status/RangesPaper.csv b/libcxx/docs/Status/RangesPaper.csv
index e2511f27e5e42..3595d29aa05d4 100644
--- a/libcxx/docs/Status/RangesPaper.csv
+++ b/libcxx/docs/Status/RangesPaper.csv
@@ -103,10 +103,10 @@ Section,Description,Dependencies,Assignee,Complete
| `ranges::iterator_t <https://llvm.org/D100255>`_
| `ranges::sentinel_t <https://llvm.org/D100269>`_
| `ranges::range_
diff erence_t <https://llvm.org/D100269>`_
-| ranges::range_size_t
+| `ranges::range_size_t <https://llvm.org/D106708>`_
| `ranges::range_value_t <https://llvm.org/D100269>`_
| `ranges::range_reference_t <https://llvm.org/D100269>`_
-| `ranges::range_rvalue_reference_t <https://llvm.org/D100269>`_",[range.access],Christopher Di Bella,In progress
+| `ranges::range_rvalue_reference_t <https://llvm.org/D100269>`_",[range.access],Christopher Di Bella,✅
`[range.sized] <http://wg21.link/range.sized>`_,"| `ranges::sized_range <https://llvm.org/D102434>`_
| `ranges::disable_sized_range <https://llvm.org/D102434>`_","| [range.primitives]
| [range.range]",Christopher Di Bella,✅
diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h
index 398f3c9010d33..6493f81e1dbab 100644
--- a/libcxx/include/__ranges/concepts.h
+++ b/libcxx/include/__ranges/concepts.h
@@ -69,6 +69,9 @@ namespace ranges {
template <class _Tp>
concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
+ template<sized_range _Rp>
+ using range_size_t = decltype(ranges::size(declval<_Rp&>()));
+
// `disable_sized_range` defined in `<__ranges/size.h>`
// [range.view], views
diff --git a/libcxx/include/ranges b/libcxx/include/ranges
index ff789738835dc..682dd6e094290 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -36,13 +36,13 @@ namespace std::ranges {
inline constexpr bool enable_borrowed_range = false;
template<class T>
- using iterator_t = decltype(ranges::begin(declval<T&>()));
- template<class T>
- using iterator_t = decltype(ranges::begin(declval<T&>()));
+ using iterator_t = decltype(ranges::begin(declval<R&>()));
template<range R>
using sentinel_t = decltype(ranges::end(declval<R&>()));
template<range R>
using range_
diff erence_t = iter_
diff erence_t<iterator_t<R>>;
+ template<sized_range R>
+ using range_size_t = decltype(ranges::size(declval<R&>()));
template<range R>
using range_value_t = iter_value_t<iterator_t<R>>;
template<range R>
diff --git a/libcxx/test/std/ranges/range.req/range.range/range_size_t.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/range_size_t.compile.pass.cpp
new file mode 100644
index 0000000000000..5460f43d7fa07
--- /dev/null
+++ b/libcxx/test/std/ranges/range.req/range.range/range_size_t.compile.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: gcc-10
+
+// template<sized_range R>
+// using range_size_t = decltype(ranges::size(declval<R&>()));
+
+#include <ranges>
+#include <concepts>
+#include <cstddef>
+
+#include "test_iterators.h"
+
+template<class T>
+concept has_range_size_t = requires { typename std::ranges::range_size_t<T>; };
+
+struct A { int *begin(); int *end(); short size(); };
+static_assert(std::same_as<std::ranges::range_size_t<A>, short>);
+static_assert(std::same_as<std::ranges::range_size_t<A&>, short>);
+static_assert(std::same_as<std::ranges::range_size_t<A&&>, short>);
+static_assert(!has_range_size_t<const A>);
+static_assert(!has_range_size_t<const A&>);
+static_assert(!has_range_size_t<const A&&>);
+
+struct B { int *begin(); int *end(); };
+static_assert(std::same_as<std::ranges::range_size_t<B>, std::size_t>);
+static_assert(std::same_as<std::ranges::range_size_t<B&>, std::size_t>);
+static_assert(std::same_as<std::ranges::range_size_t<B&&>, std::size_t>);
+static_assert(!has_range_size_t<const B>);
+static_assert(!has_range_size_t<const B&>);
+static_assert(!has_range_size_t<const B&&>);
+
+struct C { bidirectional_iterator<int*> begin(); bidirectional_iterator<int*> end(); };
+static_assert(!has_range_size_t<C>);
More information about the libcxx-commits
mailing list