[libcxx-commits] [libcxx] [libc++] Implement adjacent_view (PR #165089)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 5 12:03:56 PST 2025


================
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++20
+
+// constexpr auto operator[](difference_type n) const requires
+//        all_random_access<Const, Views...>
+
+#include <ranges>
+#include <cassert>
+
+#include "../helpers.h"
+#include "../../range_adaptor_types.h"
+
+template <std::size_t N>
+constexpr void test() {
+  int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  {
+    // random_access_range
+    std::ranges::adjacent_view<SizedRandomAccessView, N> v(SizedRandomAccessView{buffer});
+    auto it = v.begin();
+    assert(it[0] == *it);
+    assert(it[2] == *(it + 2));
+    assert(&std::get<0>(it[2]) == &buffer[2]);
----------------
ldionne wrote:

I think we should also test the other elements of the tuple, i..e `get<1>`, `get<2>`, etc. with a lvalue

https://github.com/llvm/llvm-project/pull/165089


More information about the libcxx-commits mailing list