public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100070] New: Standard library container iterator-pair constructors should check C++20 iterator concepts
@ 2021-04-13 21:34 barry.revzin at gmail dot com
  2021-04-13 21:41 ` [Bug libstdc++/100070] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: barry.revzin at gmail dot com @ 2021-04-13 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100070
           Summary: Standard library container iterator-pair constructors
                    should check C++20 iterator concepts
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

>From StackOverflow (https://stackoverflow.com/q/67081354/2069064), a user was
benchmarking code that did this:

   int convert(int);

   std::vector<int> foo(100,42);
   auto transform_range = foo | std::ranges::views::transform(convert);
   std::vector<int> fooTimesTwo(transform_range.begin(),
transform_range.end());

And found it to be much slower than their initial implementation that did not
use ranges. This is because while transform_range is a C++20 random access
range, it is only a C++17 input range. 

libstdc++'s decision is based entirely on iterator_category
(https://github.com/gcc-mirror/gcc/blob/8084ab15a3e300e3b2c537e56e0f3a1b00778aec/libstdc%2B%2B-v3/include/bits/stl_vector.h#L652-L659)
which does the best you can with an input range: just loop and emplace.

But if it instead checked for forward_iterator and random_access_iterator (the
concept), this construction case could be handled efficiently (i.e. as a single
allocation). I think that should safe? Checking for random_access_iterator
checks the tag before checking for the validity of operator-?

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-04-22 17:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 21:34 [Bug c++/100070] New: Standard library container iterator-pair constructors should check C++20 iterator concepts barry.revzin at gmail dot com
2021-04-13 21:41 ` [Bug libstdc++/100070] " redi at gcc dot gnu.org
2021-04-13 21:48 ` redi at gcc dot gnu.org
2021-04-13 22:11 ` redi at gcc dot gnu.org
2021-04-13 22:15 ` redi at gcc dot gnu.org
2021-04-14 11:09 ` redi at gcc dot gnu.org
2021-04-14 11:10 ` redi at gcc dot gnu.org
2021-04-14 11:23 ` redi at gcc dot gnu.org
2021-04-14 16:41 ` redi at gcc dot gnu.org
2021-04-14 17:34 ` ppalka at gcc dot gnu.org
2021-10-12 21:50 ` ppalka at gcc dot gnu.org
2021-10-12 22:56 ` redi at gcc dot gnu.org
2022-04-22 17:33 ` redi at gcc dot gnu.org

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).