[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:54 PST 2025
================
@@ -0,0 +1,242 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// Test std::views::adjacent<N>
+
+#include <concepts>
+#include <cstddef>
+#include <iterator>
+#include <ranges>
+#include <type_traits>
+
+#include "../range_adaptor_types.h"
+
+template <std::size_t N>
+constexpr void test_constraints() {
+ // needs to be a range
+ static_assert(std::is_invocable_v<decltype((std::views::adjacent<N>)), std::ranges::empty_view<int>>);
+ static_assert(!std::is_invocable_v<decltype((std::views::adjacent<N>)), int>);
+
+ // underlying needs to be forward_range
+ static_assert(!std::is_invocable_v<decltype((std::views::adjacent<N>)), InputCommonView>);
+ static_assert(std::is_invocable_v<decltype((std::views::adjacent<N>)), ForwardSizedView>);
+}
+
+constexpr void test_pairwise_constraints() {
+ // needs to be a range
+ static_assert(std::is_invocable_v<decltype((std::views::pairwise)), std::ranges::empty_view<int>>);
+ static_assert(!std::is_invocable_v<decltype((std::views::pairwise)), int>);
+
+ // underlying needs to be forward_range
+ static_assert(!std::is_invocable_v<decltype((std::views::pairwise)), InputCommonView>);
+ static_assert(std::is_invocable_v<decltype((std::views::pairwise)), ForwardSizedView>);
+}
+
+constexpr void test_all_constraints() {
+ test_pairwise_constraints();
+ test_constraints<0>();
+ test_constraints<1>();
+ test_constraints<2>();
+ test_constraints<3>();
+ test_constraints<5>();
+}
+
+constexpr void test_zero_case() {
----------------
ldionne wrote:
```suggestion
static constexpr void test_zero_case() {
```
Suggestion: this will make the compiler issue a warning if you forget to call the function anywhere in the file.
https://github.com/llvm/llvm-project/pull/165089
More information about the libcxx-commits
mailing list