[libcxx-commits] [libcxx] [libc++] P3168R2 Give std::optional Range Support (PR #146491)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 2 02:46:06 PDT 2025
================
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: std-at-least-c++26
+
+#include <cassert>
+#include <optional>
+
+constexpr bool test() {
+ constexpr std::optional<int> val = 2;
+ for (const auto& elem : val)
+ if (elem != 2)
+ return false;
+ return true;
+}
+
+int main() {
+ static_assert(test());
----------------
frederick-vs-ja wrote:
We generally test `constexpr` functionality like this:
```suggestion
test();
static_assert(test());
```
https://github.com/llvm/llvm-project/pull/146491
More information about the libcxx-commits
mailing list