From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 685A0385843A; Tue, 25 Oct 2022 03:36:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 685A0385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666668983; bh=fqvupfwHZERkT2eGtqRJNAUTzroK/eJnbmM5ICg0J/Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=H8iaIKJBr18o1sdm+m8qC2cOY8LGvAk/OvcUDrFgoAskQVNYIy/y45Ra4rxTCjwMQ lHZKYxZXbzTj0ur+ztFuI5VlQZfzxkgpYzg/301CPVAQqk61dOQhENO/zH3+4ejSXF HGdTKdqFlr6qCOFevXnHQBqYllEhtPHVSTsdhTLc= From: "unlvsur at live dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107367] All standard library algorithms should optimize to pointers internally when they are contiguous iterators after C++20 Date: Tue, 25 Oct 2022 03:36:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: unlvsur at live dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107367 --- Comment #2 from cqwrteur --- (In reply to cqwrteur from comment #1) > This optimization will prevent duplications of templates over iterators a= nd > pointers. (vector::iterator and int* duplications for example) >=20 > For example: >=20 > https://godbolt.org/z/9zEajxxa8 > vs > https://godbolt.org/z/n61vEddj1 >=20 > 579 vs 879 For debugging. You can do something like this template concept can_optimize_to_pointer_impl =3D=20 #ifdef _GLIBCXX_DEBUG false; #else std::contiguous_iterator&&!std::is_pointer_v; #endif template constexpr void my_sort(ForwardIterator first,ForwardIterator last) { if constexpr(can_optimize_to_pointer_impl) { std::sort(std::to_address(first),std::to_address(last)); } else { std::sort(first,last); } } https://godbolt.org/z/jj38MoWen=