<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - <iterator> C++14 cbegin/cend crbegin/crend definitions don't see all overloads of begin/end rbegin/rend"
href="http://llvm.org/bugs/show_bug.cgi?id=17934">17934</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td><iterator> C++14 cbegin/cend crbegin/crend definitions don't see all overloads of begin/end rbegin/rend
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>hhinnant@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>peter.sommerlad@hsr.ch
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=11541" name="attach_11541" title="corrected <iterator> file">attachment 11541</a> <a href="attachment.cgi?id=11541&action=edit" title="corrected <iterator> file">[details]</a></span>
corrected <iterator> file
when using cbegin/cend or crbegin/crend with arrays the code doesn't compile.
The reason is that the template definitions don't see all defined overloads of
the functions they rely upon. the array overloads of begin/end rbegin/rend come
later in the file <iostream>
Because we are on namespace level sequencing of function definitions is
important and a template function relying on another function must have all
relevant overloads visisble before the template definition.
Moving the overloads of begin/end rbegin/rend for arrays in front of the
definitions of cbegin/cend crbegin/crend respecitvely fixes this issue.
I'll attach a fixed <iterator>
Example code demonstrating the bug:
#include <iostream>
#include <iterator>
using std::crbegin;
using std::crend;
template <typename CONT>
void reverse_printer(CONT &&c){
for (auto it=crbegin(c); it!=crend(c); ++it){
std::cout << *it << ", ";
}
std::cout << '\n';
}
int main(){
auto l={1,2,3,4,5};
reverse_printer(l);
int a[]={5,4,3,2,1};
reverse_printer(a); // fails to compile
}</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>