http://llvm.org/bugs/show_bug.cgi?id=17934
Bug ID: 17934
Summary: <iterator> C++14 cbegin/cend crbegin/crend definitions
don't see all overloads of begin/end rbegin/rend
Product: libc++
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
Created attachment 11541
--> http://llvm.org/bugs/attachment.cgi?id=11541&action=edit
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
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs