[libcxx-commits] [libcxx] [libc++][ranges] LWG4001: `iota_view` should provide `empty` (PR #79687)

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 31 14:06:05 PDT 2024


================
@@ -0,0 +1,136 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// constexpr bool empty() const;
+
+#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <utility>
+#include <vector>
+
+#include "types.h"
+
+template <typename R>
+concept HasFreeEmpty = requires(R r) { std::ranges::empty(r); };
+
+template <typename R>
+concept HasMemberEmpty = requires(R r) {
+  { r.empty() } -> std::same_as<bool>;
+};
+
+constexpr void test_empty_iota() {
+  std::vector<int> ev;
+
+  // Both parameters are non-const
+  {
+    auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(ev));
+
+    static_assert(HasFreeEmpty<decltype(iv)>);
----------------
var-const wrote:

Nit: normally, the ranges tests follow a pattern where constraints are tested in a separate block before testing the actual function -- can you please do the same? It's mostly for consistency, but IMO it's also easier to make sure we're testing all the constraints when the tests are all next to each other and not spread out in the file.

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


More information about the libcxx-commits mailing list