c++/2138: trouble with STL's distance function

Wolfgang Bangerth wolfgang.bangerth@iwr.uni-heidelberg.de
Thu Mar 1 06:01:00 GMT 2001


Hi there,
based on the analysis of Volker, I guess that indeed the concepts checks
are wrong: the standard requires that forward operators only have an index
operator with semantics
  a[n]   <->   *(a+n)
I cannot see that it must actually be assignable. (This is all [24.1.5].)

If that were so, then the appended patch would be correct, and it indeed
fixes his bug. (Unfortunately, it still doesn't fix c++/1657, which I
hoped it would, but that seems more like a memory corruption bug. sigh :])

Regards
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth          email: wolfgang.bangerth@iwr.uni-heidelberg.de
                             www: http://gaia.iwr.uni-heidelberg.de/~wolf

Index: concept_checks.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/concept_checks.h,v
retrieving revision 1.1
diff -c -r1.1 concept_checks.h
*** concept_checks.h	2000/10/05 11:27:01	1.1
--- concept_checks.h	2001/03/01 13:54:00
***************
*** 473,479 ****
      return __n;
    }
    template <class _Exp, class _Type, class _Distance>
!   static _Type
    __element_access_operator_requirement_violation(_Exp __x, _Type*,
                                                    _Distance __n) {
      return __x[__n];
--- 473,479 ----
      return __n;
    }
    template <class _Exp, class _Type, class _Distance>
!   static _Type &
    __element_access_operator_requirement_violation(_Exp __x, _Type*,
                                                    _Distance __n) {
      return __x[__n];



More information about the Gcc-patches mailing list