[libcxx-commits] [libcxx] [libc++] Resolve LWG4308, correct `iterator` availability for `optional<T&>` (PR #173948)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 30 17:51:53 PST 2025
================
@@ -19,6 +19,21 @@
#include <type_traits>
#include <utility>
+template <typename T>
+concept has_iterator = requires { typename T::iterator; };
+
+template <typename T>
+concept has_const_iterator = requires { typename T::const_iterator; };
+
+template <typename T>
+concept has_both_iterators = has_iterator<T> && has_const_iterator<T>;
+
+template <typename T>
+concept only_has_iterator = has_iterator<T> && !has_const_iterator<T>;
+
+template <typename T>
+concept has_no_iterators = !has_iterator<T> && !has_const_iterator<T>;
+
template <typename T>
constexpr bool test_range_concept() {
return std::ranges::range<std::optional<T>>;
----------------
frederick-vs-ja wrote:
It seems more senseful to make this a `concept` or `constexpr bool` variable template.
https://github.com/llvm/llvm-project/pull/173948
More information about the libcxx-commits
mailing list