https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://en.cppreference.com/w/cpp/iterator/advance says "InputIt must meet the
requirements of LegacyInputIterator."

https://en.cppreference.com/w/cpp/named_req/InputIterator gives a sample
concept you can use to test whether something meets those requirements. The
iterator_t<iota_view<int64_t, int64_t>> type does not satisfy that concept.

I think GCC is behaving according to the standard.

You can use std::ranges::advance because that requires
std::input_or_output_iterator, which is satisfied by your iota_view's iterator.


#include <ranges>

int main() {
  using type = std::int64_t; // using type = int works!
  auto v = std::views::iota(static_cast<type>(0), static_cast<type>(100));
  auto b = v.begin();

  static_assert( ! __LegacyInputIterator<decltype(b)> );
  // So this can't work:
  // std::advance(b, 1);

  static_assert( std::input_iterator<decltype(b)> );
  // So this can work:
  std::ranges::advance(b, static_cast<type>(1));
}

Reply via email to