<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Enhancement: Please add a builtin to count bindings in [dcl.struct.bind]"
href="https://bugs.llvm.org/show_bug.cgi?id=46704">46704</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Enhancement: Please add a builtin to count bindings in [dcl.struct.bind]
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>wjwray@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>(Submitting simultaneous requests for each of Clang, GCC 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.
GCC ticket <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96185">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96185</a>
MSVC
<a href="https://developercommunity.visualstudio.com/idea/1111203/enhancement-please-add-a-builtin-to-count-bindings.html">https://developercommunity.visualstudio.com/idea/1111203/enhancement-please-add-a-builtin-to-count-bindings.html</a>#</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>