[libcxx-commits] [libcxx] [libc++] Implement ranges::iota (PR #68494)
James E T Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 28 12:48:54 PDT 2024
================
@@ -1083,6 +1083,27 @@ rvalue_iterator(T*) -> rvalue_iterator<T>;
static_assert(std::random_access_iterator<rvalue_iterator<int*>>);
+// The ProxyDiffTBase allows us to conditionally specify Proxy<T>::difference_type
+// which we need in certain situations. For example when we want
+// std::weakly_incrementable<Proxy<T>> to be true.
+template <class T>
+struct ProxyDiffTBase {};
+
+template <class T>
+ requires requires { std::iter_difference_t<T>{}; }
+struct ProxyDiffTBase<T> {
+ using difference_type = std::iter_difference_t<T>;
+};
+
+// These concepts allow us to conditionally add the pre-/postfix operators
+// when T also supports those member functions. Like ProxyDiffTBase, this
+// is necessary when we want std::weakly_incrementable<Proxy<T>> to be true.
+template <class T>
+concept HasPreIncrementOp = requires(T const& obj) { ++obj; };
+
+template <class T>
+concept HasPostIncrementOp = requires(T const& obj) { obj++; };
+
----------------
jamesETsmith wrote:
My motivation for putting them in `test_iterators.h` was that other features in the future may require the same flexibility, but since I don't have any explicitly in mind it's a weak argument on my part.
Do you feel strongly about this? If you do, I can rollback my changes to `test_iterators.h` and have a specialized version of `Proxy` for the `ranges::iota` tests, just lmk.
https://github.com/llvm/llvm-project/pull/68494
More information about the libcxx-commits
mailing list