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

履歴 編集

function
<ranges>

std::ranges::filter_view::iterator::operator--(C++20)

constexpr iterator& operator++() requires bidirectional_range<V>;      // (1)
constexpr iterator operator--(int) requires bidirectional_range<V>;    // (2)

概要

イテレータを1つ進める。

効果

(1)は、

do
  --current_;
while (!invoke(*parent_->pred_, *current_));
return *this;

と等しい。

(3)は、

auto tmp = *this;
--*this;
return tmp;

と等しい。

#include <ranges>
#include <vector>

int main() {
  using std::ranges::filter_view;
  using std::ranges::iterator_t;

  std::vector<int> vec = {0, 1, 2, 3, 4, 5};

  filter_view fv{vec, [](int x){ return x % 2 == 0; }};

  iterator_t<filter_view> i(fv, vec.begin());

  std::cout << *i << `\n`;
  i--;
  std::cout << *i << `\n`;
  i--;
  std::cout << *i << `\n`;
}

出力

0
2
4

バージョン

言語

  • C++20

処理系

参照