[libcxx-commits] [PATCH] D141699: [In Progress][libc++][ranges] Implement P2474R2(`views::repeat`).

Yurong via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 15 10:03:34 PST 2023


yronglin marked 4 inline comments as done.
yronglin added inline comments.


================
Comment at: libcxx/include/__ranges/repeat_view.h:31
+
+#define _LIBCPP_STD_VER 23
+
----------------
philnik wrote:
> This seems wrong.
Sorry, I forget it..., it was used to make my vscode hightlight the code, I have removed this.


================
Comment at: libcxx/include/__ranges/repeat_view.h:43
+private:
+  struct __iterator;
+
----------------
philnik wrote:
> You can't make this a member of `repeat_view` because it makes specializing traits impossible. Instead, make it a class inside `namespace std` and add an alias here. You can look at `istream_view` for an example of this.
I have updated the patch, and many thanks for your help! But it's looks like a little bit not very close to the words.
```
namespace std::ranges {
  template<copy_constructible W, semiregular Bound = unreachable_sentinel_t>
    requires (is_object_v<W> && same_as<W, remove_cv_t<W>>
      && (is-integer-like<Bound> || same_as<Bound, unreachable_sentinel_t>))
  class repeat_view : public view_interface<repeat_view<W, Bound>> {
  private:
    // [range.repeat.iterator], class range_view::iterator
    struct iterator;

    copyable-box<W> value_ = W(); // exposition only, see [range.copy.wrap]
    Bound bound_ = Bound(); // exposition only

  public:
    repeat_view() requires default_initializable<W> = default;

    constexpr explicit repeat_view(const W & value, Bound bound = Bound());
    constexpr explicit repeat_view(W && value, Bound bound = Bound());
    template<class... WArgs, class... BoundArgs>
      requires constructible_from<W, WArgs...>
        && constructible_from<Bound, BoundArgs...>
    constexpr explicit repeat_view(piecewise_construct_t,
      tuple<WArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});

    constexpr iterator begin() const;
    constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>);
    constexpr unreachable_sentinel_t end() const noexcept;

    constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);
  };

  template<class W, class Bound>
    repeat_view(W, Bound) -> repeat_view<W, Bound>;
}

```


================
Comment at: libcxx/include/__ranges/repeat_view.h:194
+    requires __can_unbound_repeat_view<_Tp>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __value) const {
+    return repeat_view(std::forward<_Tp>(__value));
----------------
philnik wrote:
> This should be `_LIBCPP_NODISCARD_EXT`. Please add a test.
> This should be `_LIBCPP_NODISCARD_EXT`. Please add a test.

Thanks for your reminder, I'll add tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141699/new/

https://reviews.llvm.org/D141699



More information about the libcxx-commits mailing list