zeusdeux / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

StringPiece is not compatible with std::sort #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

        char const *str = "abcab";
        re2::StringPiece s1(str, 3), s2(str + 3, 2);

       std::vector<re2::StringPiece> ss;
        ss.push_back(s1);
        ss.push_back(s2);

        sort(ss.begin(), ss.end());

What is the expected output? What do you see instead?

Compiled correctly.

/usr/include/c++/4.2/bits/stl_algo.h:100: error: no match for 'operator<' in 
'__b < __c'

/usr/include/c++/4.2/bits/stl_algo.h: 
In function '_RandomAccessIterator 
std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp) 
[with _RandomAccessIterator = __gnu_cxx::__normal_iterator<re2::StringPiece*, 
std::vector<re2::StringPiece, std::allocator<re2::StringPiece> > >, _Tp = 
re2::StringPiece]':

/usr/include/c++/4.2/bits/stl_algo.h:2758:   instantiated from 'void 
std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) 
[with _RandomAccessIterator = __gnu_cxx::__normal_iterator<re2::StringPiece*, 
std::vector<re2::StringPiece, std::allocator<re2::StringPiece> > >, _Size = 
int]'

/usr/include/c++/4.2/bits/stl_algo.h:2829:   instantiated from 'void 
std::sort(_RandomAccessIterator, _RandomAccessIterator) [with 
_RandomAccessIterator = __gnu_cxx::__normal_iterator<re2::StringPiece*, 
std::vector<re2::StringPiece, std::allocator<re2::StringPiece> > >]'

What version of the product are you using? On what operating system?

Latest release / GCC 4.2.1 / FreeBSD 8.0

Original issue reported on code.google.com by YangA...@gmail.com on 22 Apr 2011 at 7:31

GoogleCodeExporter commented 9 years ago
I solve this issue by moving compare operators of StringPiece to re2 namespace.
Definition of operator== in stringpiece.cpp requires modification, too.

Original comment by YangA...@gmail.com on 22 Apr 2011 at 8:11

GoogleCodeExporter commented 9 years ago
Patch I mentioned in comment 1 is ok when I used simple test file but failed in 
a real project. After all, I  made all operators inlined in re2 namespace.

Original comment by YangA...@gmail.com on 22 Apr 2011 at 5:59

GoogleCodeExporter commented 9 years ago
This issue was closed by revision af73701f0348.

Original comment by rsc@swtch.com on 1 May 2011 at 7:26