This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: operator== missing on std::__debug::map<>::iterator
Hi
Check this minimalistic example that shows the behaviour I'm describing:
piotr@gominola:1:~$ g++ -std=c++11 -o debug_iter debug_iter.cpp && ./debug_iter
==
piotr@gominola:0:~$ g++ -std=c++11 -o debug_iter debug_iter.cpp -D_GLIBCXX_DEBUG
debug_iter.cpp: In member function ‘bool itor::operator==(itor) const’:
debug_iter.cpp:22:15: error: ‘operator==’ is not a member of
‘std::__debug::map<int, int>::iterator {aka
__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<const
int, int> >, std::__debug::map<int, int> >}’
piotr@gominola:1:~$
gcc version 4.7.2 (Debian 4.7.2-4)
Pedro.
#include <iostream>
#include <map>
using namespace std;
typedef map<int, int> m_t;
class itor: private m_t::iterator
{
public:
itor(const m_t::iterator& other):
m_t::iterator(other)
{
}
bool operator==(itor right) const
{
return m_t::iterator::operator==(right);
}
};
int main(int argc, char *argv[])
{
m_t m;
itor i = m.begin();
itor j = m.end();
if (i == j)
cout << "==" << endl;
}
On Mon, Dec 10, 2012 at 2:17 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
>
> On 12/10/2012 02:00 PM, Pedro Larroy wrote:
>>
>> Hi
>>
>> I'm trying to compile with -D_GLIBCXX_DEBUG and I get an error which
>> doesn't happen without the previous macro
>>
>> There's an implementation of iterator inheriting privately from
>> std::__debug::map<......>::iterator and calling for operator==
>> operator== in the 'std::__debug::map<......>::iterator
>>
>> I get the following error:
>>
>> error: 'operator==' is not a member of
>> 'std::__debug::map<......>::iterator
>>
>> Is operator== missing intentionally from the iterator class?
>
> Please post a self-contained testcase exhibiting the problem. As a general
> principle, any kind of code compiling in normal mode is supposed to compile
> in debug-mode and the debug-mode iterator details are pretty old, thus I
> would be surprised if nobody noticed before such a macroscopic issue as
> operator== missing (and most likely we would see dozens of fails when
> running make check-debug) . Indeed something like this compiles fine in all
> the active branches with -D_GLIBCXX_DEBUG:
>
> #include <map>
>
> int main()
> {
> std::map<int, int> m;
>
> auto it1 = m.begin();
> auto it2 = m.end();
>
> if (it1 == it2)
> ;
> }
>
> Note, just in case isn't obvious, that operator== is a *free* function, not
> a member function of the iterator class (both for normal mode and debug-mode
> iterator)
>
> Paolo.