From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B6F2E3856621; Thu, 8 Jun 2023 10:17:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6F2E3856621 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686219454; bh=BZ9se0LqBPTnWvYJeL8WPnYLduuR71qCJy2F5EWdqGQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DlHKgKVn8uhm6a34DLvH+/t1ulZ93sPZCdDnsT6gnXOyC+bjbqI48hk4TXU4llQts TFbgjxj8hJrME9GiyGLEkgk1p200UDx0o+qxr3hYvqbmj/bwI5Fs11KhFZdmZXykvV KAQm2AQ+g9c4TcGoDDvaG9URSadJiJ9hRY1OM1d8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110167] excessive compile time when optimizing std::to_array Date: Thu, 08 Jun 2023 10:17:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: compile-time-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D110167 --- Comment #2 from Jonathan Wakely --- The "obvious" alternative impl using a lambda expression is even slower: template struct array { int data[N]; }; template struct seq { }; #ifndef USE_LAMBDA template array to_array_impl(int (&a)[sizeof...(Idx)], seq) { return {{a[Idx]...}}; } #endif template array to_array(int (&a)[N]) { #ifndef USE_LAMBDA return to_array_impl(a, seq<__integer_pack(N)...>{}); #else return [&a](seq) { return array{{ a[I]... }}; }(seq<__integer_pack(N)...>{}); #endif } constexpr int S =3D 2000; int f[S]; array g(void) { return to_array(f); }=