• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    class template
    <ranges>

    std::ranges::repeat_view::iterator

    概要

    repeat_viewのイテレータ。

    このクラスの名前は規定されておらず、振る舞いのみが規定されている。

    このクラスの型を取得したい場合、iterator_tを使用できる。

    実装例

    namespace std::ranges {
      template<move_constructible T, semiregular Bound = unreachable_sentinel_t>
        requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
                  (is-integer-like<Bound> || same_as<Bound, unreachable_sentinel_t>))
      class repeat_view<T, Bound>::iterator {
      private:
        using index_type = conditional_t<same_as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>;
        const T* value_ = nullptr;
        index_type current_ = index_type();
    
        constexpr explicit iterator(const T* value, index_type b = index_type())
          : value_{value}
          , current_{b}
        {
        }
    
      public:
        using iterator_concept = random_access_iterator_tag;
        using iterator_category = random_access_iterator_tag;
        using value_type = T;
        using difference_type = conditional_t<is-signed-integer-like<index_type>,
            index_type,
            iota_diff_t(index_type)>;
    
        iterator() = default;
    
        constexpr const T& operator*() const noexcept {
          return *value_;
        }
    
        constexpr iterator& operator++() {
          ++current_;
          return *this;
        }
        constexpr iterator operator++(int) {
          auto tmp = *this;
          ++*this;
          return tmp;
        }
    
        constexpr iterator& operator--() {
          --current_;
          return *this;
        }
        constexpr iterator operator--(int) {
          auto tmp = *this;
          --*this;
          return tmp;
        }
    
        constexpr iterator& operator+=(difference_type n) {
          current_ += n;
          return *this;
        }
        constexpr iterator& operator-=(difference_type n) {
          current_ -= n;
          return *this;
        }
        constexpr const T& operator[](difference_type n) const noexcept {
          return *(*this + n);
        }
    
        friend constexpr bool operator==(const iterator& x, const iterator& y) {
          return x.current_ == y.current_;
        }
        friend constexpr auto operator<=>(const iterator& x, const iterator& y) {
          return x.current_ <=> y.current_;
        }
    
        friend constexpr iterator operator+(iterator i, difference_type n) {
          i += n;
          return i;
        }
        friend constexpr iterator operator+(difference_type n, iterator i) {
          i += n;
          return i;
        }
    
        friend constexpr iterator operator-(iterator i, difference_type n) {
          i -= n;
          return i;
        }
        friend constexpr difference_type operator-(const iterator& x, const iterator& y) {
          return static_cast<difference_type>(x.current_) - static_cast<difference_type>(y.current_);
        }
      };
    }
    

    バージョン

    言語

    • C++23

    処理系

    参照