From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 01D94386102F; Mon, 13 Jul 2020 13:16:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01D94386102F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594646219; bh=oammJOQsul0l4R2L30s1FyEPDwrbxjDGQnGzZNMmehA=; h=From:To:Subject:Date:From; b=dQHRblo1ywum311JD7TFfCKnKZzncsogxRoiLmmn33Jz65quDGM5S/xANxLppxzus 73JrOulJ3yC3kC9QGQP59NcyNcTgLEChx3a2LjZzcU4ZHe4vEBKoJOMi1sBQexiWSD C609paZsamlfxVGC/Js0o3+IBkTrB7ob9RLl8q/8= From: "wjwray at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96185] New: Enhancement: Please add a builtin to count bindings in [dcl.struct.bind] Date: Mon, 13 Jul 2020 13:16:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wjwray at gmail 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2020 13:16:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96185 Bug ID: 96185 Summary: Enhancement: Please add a builtin to count bindings in [dcl.struct.bind] Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wjwray at gmail dot com Target Milestone: --- (Submitting simultaneous requests for each of GCC, Clang and MSVC. Coordination between vendors will be beneficial for portability.) Please add a builtin to count the bindings in [dcl.struct.bind]. A structured-bindable object has one of three types T: Case 1: array type Case 2: tuple access protocol; tuple_size, tuple_element, get Case 3: else, class types with restricted member data location & access P2141 "Aggregates are named tuples" proposes automatic tuple-like protocol for Case 3 types, in particular a generalisation of std::tuple_size. This request is for a builtin exposing the field count of a Case 3 type (so can be used to implement P2141's generalized std::tuple_size). Counting bindings is key; it immediately opens up binding-based reflection. Specification points (to be discussed & agreed between implementors) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Naming suggestions: __builtin_tuple_size, __builtin_binding_count ? What value type? What value for an unsupported, non-bindable type? Should the builtin work for Case 1 array and/or Case 2 tuple-like T? E.g. given a statement SB : auto&& [b1,... bN] =3D std::declval(= ); decomposing a T into N bindings: - If SB is well formed then the builtin evaluates to integer constant N - Else If T is an empty class type then evaluate to 0 - Else evaluate to -1 ?? size_t(-1) ?? false ?? The empty class type exception is a convenience (c.f. std::is_empty) and future-proofing in case variadic bindings allow the empty pack case. What about access - should the builtin be sensitive to scope? (I think not.)(c.f. P0969 DR allowing binding to accessible members.) Please discuss with other implementors and agree on a portable builtin. Thanks for your consideration.=