[libcxx-commits] [libcxx] [libc++][ranges] Implement `ranges::stride_view`. (PR #65200)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 2 15:34:09 PST 2024
================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// friend constexpr void iter_swap(__iterator const& __x, __iterator const& __y)
+// noexcept(noexcept(ranges::iter_swap(__x.__current_, __y.__current_)))
+// requires indirectly_swappable<iterator_t<_Base>>
+
+#include <ranges>
+
+#include "../types.h"
+#include "__ranges/concepts.h"
+
+template <typename T>
+concept swappable = requires(T&& t, T&& u) { std::ranges::iter_swap(t, u); };
+
+constexpr bool test() {
+ {
+ int iter_move_counter_one(0);
+ int iter_move_counter_two(0);
+ using View = IterSwapRange<true, true>;
+ using StrideView = std::ranges::stride_view<View>;
+ auto svba = StrideView(View(&iter_move_counter_one), 1).begin();
+ auto svbb = StrideView(View(&iter_move_counter_two), 1).begin();
+
+ static_assert(swappable<std::ranges::iterator_t<StrideView>>);
+ static_assert(noexcept(std::ranges::iter_swap(svba, svbb)));
+
+ std::ranges::iter_swap(svba, svbb);
----------------
cjdb wrote:
We should check that the values were swapped.
https://github.com/llvm/llvm-project/pull/65200
More information about the libcxx-commits
mailing list