public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
Date: Thu, 02 Sep 2021 21:59:19 +0000	[thread overview]
Message-ID: <bug-102181-4-dO87dgKdOL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102181-4@http.gcc.gnu.org/bugzilla/>

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));
}

  parent reply	other threads:[~2021-09-02 21:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 20:28 [Bug libstdc++/102181] New: " raffael at casagrande dot ch
2021-09-02 21:36 ` [Bug libstdc++/102181] " redi at gcc dot gnu.org
2021-09-02 21:44 ` redi at gcc dot gnu.org
2021-09-02 21:51 ` raffael at casagrande dot ch
2021-09-02 21:59 ` redi at gcc dot gnu.org [this message]
2021-09-02 22:13 ` redi at gcc dot gnu.org
2021-09-02 23:35 ` redi at gcc dot gnu.org
2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:11 ` [Bug libstdc++/102181] [DR 3197] " redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102181-4-dO87dgKdOL@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).