Compiler version: 7.1.3088
Is this a bug in the compiler:
If I use a reverse_iterator as an operand to the != operator in a const
member function of a class I get a compiler error. However, if I assign that
reverse_iterator to a const_reverse_iterator and then use the
const_reverse_iterator as an operand to the != operator then I don't get any
compiler errors. Yet they both do the same thing. Here is the code snippet
that reproduces the problem:
#include <list>
class Qwerty2
{
public:
void foo() const
{
//---------------------------------------------
//Causes compiler errors.
//---------------------------------------------
if( m_ReverseIter != list1.rend() ) { }
//---------------------------------------------
//Does not cause compiler errors but does the same thing.
//---------------------------------------------
//IntList::const_reverse_iterator rItCurrent = m_ReverseIter;
//if( rItCurrent != list1.rend() ) { }
//Same thing as above, this works too.
//if( (IntList::const_reverse_iterator)m_ReverseIter != list1.rend() ) { }
}
private:
typedef std::list<int> IntList;
IntList list1;
IntList::reverse_iterator m_ReverseIter;
};
Here is a sample of the errors I get:
Compiling...
T2.cpp
T2.cpp(11) : error C2784: 'bool std::operator !=(const std::list<_Ty,_Alloc>
&,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for
'const std::list<_Ty,_Ax> &' from 'const std::list<_Ty>::reverse_iterator'
with
[
_Ty=int
]
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\list(984) : see declaration of 'std::operator`!=''
T2.cpp(11) : error C2676: binary '!=' : 'const
std::list<_Ty>::reverse_iterator' does not define this operator or a
conversion to a type acceptable to the predefined operator
with
[
_Ty=int
]
Bo Persson - 16 Oct 2005 08:47 GMT
> Compiler version: 7.1.3088
>
> Is this a bug in the compiler:
No, not really.
> If I use a reverse_iterator as an operand to the != operator in a
> const
[quoted text clipped - 4 lines]
> get any
> compiler errors. Yet they both do the same thing.
There are suggestions to add this to a future revision of the
language, but it is not yet a requirement in the Standard.
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#280
This issue has status Ready, meaning that it is ready for a vote by
the standards committee, but that hasn't happened yet.
Bo Persson
qwerty2_reverse_iterator - 16 Oct 2005 23:25 GMT
Thanks!
> > Compiler version: 7.1.3088
> >
[quoted text clipped - 20 lines]
>
> Bo Persson