[cfe-dev] [libc++] Comparing vector<T*>::iterator to vector<T*>::const_iterator&
Ryuta Suzuki
ryuuta at gmail.com
Fri Jul 22 22:29:32 PDT 2011
Hi,
The following program cannot be compiled with libc++
#include <vector>
#include <unordered_map>
typedef std::vector<int*> KernelVector;
typedef std::unordered_map<int*,KernelVector> KernelVectorMap;
int main()
{
KernelVectorMap::const_iterator kernel;
KernelVector::const_iterator subkernel = kernel->second.begin();
std::distance( kernel->second.begin(), subkernel );
return 0;
}
clang++ -std=c++0x -stdlib=libc++ ./const_iterator.cpp
./const_iterator.cpp:12:3: error: no matching function for call to
'distance'
std::distance( kernel->second.begin(), subkernel );
^~~~~~~~~~~~~
/usr/include/c++/v1/iterator:478:1: note: candidate template ignored:
deduced conflicting types for parameter
'_InputIter' ('std::__1::__wrap_iter<int **>' vs.
'std::__1::__wrap_iter<int *const *>')
distance(_InputIter __first, _InputIter __last)
^
1 error generated.
or
g++ -std=c++0x -I /usr/include/c++/v1/ ./const_iterator.cpp
./const_iterator.cpp: In function ‘int main()’:
./const_iterator.cpp:12:52: error: no matching function for call to
‘distance(std::__1::vector<int*>::iterator,
std::__1::vector<int*>::const_iterator&)’
./const_iterator.cpp:12:52: note: candidate is:
/usr/include/c++/v1/iterator:479:47: note: template<class _InputIter>
typename std::__1::iterator_traits::difference_type
std::__1::distance(_InputIter, _InputIter)
Please note that there's no error produced when libstdc++ used.
My expectation was that libc++ silently convert iterator to const_iterator
if necessary, but I guess I'm wrong.
Any comments will be greatly appreciated.
Thanks,
Ryuta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110723/6e2b05ac/attachment.html>
More information about the cfe-dev
mailing list