public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96185] New: Enhancement: Please add a builtin to count bindings in [dcl.struct.bind]
@ 2020-07-13 13:16 wjwray at gmail dot com
  2020-07-13 13:24 ` [Bug c++/96185] " wjwray at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: wjwray at gmail dot com @ 2020-07-13 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

            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<T>, tuple_element<I,T>, get<I>
  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)
====================
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<T,N> :    auto&& [b1,... bN] = std::declval<T>();
decomposing a T into N bindings:

- If SB<T,N> 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<T>)
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.

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

end of thread, other threads:[~2020-07-14 16:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 13:16 [Bug c++/96185] New: Enhancement: Please add a builtin to count bindings in [dcl.struct.bind] wjwray at gmail dot com
2020-07-13 13:24 ` [Bug c++/96185] " wjwray at gmail dot com
2020-07-14  6:49 ` rguenth at gcc dot gnu.org
2020-07-14 14:56 ` wjwray at gmail dot com
2020-07-14 15:17 ` redi at gcc dot gnu.org
2020-07-14 15:19 ` redi at gcc dot gnu.org
2020-07-14 15:22 ` jakub at gcc dot gnu.org
2020-07-14 15:39 ` wjwray at gmail dot com
2020-07-14 15:40 ` wjwray at gmail dot com
2020-07-14 16:08 ` redi at gcc dot gnu.org
2020-07-14 16:32 ` wjwray at gmail dot com

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