From -9031493827811854807
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7eaa8faac8da5016,start
X-Google-Attributes: gidf78e5,public
From: "Darin Adler" <darin@bentspoon.com>
Subject: Defect Report: member == in container iterators considered harmful
Date: 1999/08/16
Message-ID: <7p4nj8$n3u@enews4.newsguy.com>#1/1
X-Deja-AN: 513421653
X-NNTP-Posting-Host: news.newsdawg.com
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset="US-ASCII"
Organization: http://extra.newsguy.com
Mime-Version: 1.0
Newsgroups: comp.std.c++
Originator: clamage@taumet


[ moderator's note: forwarded to C++ committee for handling. -sdc ]

Some standard containers define iterator classes to fulfill the requirements
described in 23.1 [lib.container.requirements]. This states that iterator
must be convertible to const_iterator. However, the following code is not
guaranteed to work:

    bool check_equal(std::deque<int>::iterator i,
        std::deque<int>::const_iterator ci)
    {
        return i == ci;
    }

The reason for this is that there's no requirement that the == operator be
defined as a non-member function. The implementation is allowed to use a
member function, which prevents the case above from working. Conversions
can't be applied to the argument on the left side of the operator.

The iterator requirements in section 24.1 [lib.iterator.requirements] are
sufficient to define each iterator class on its own, but state nothing one
way or another about cases where there's a type conversion involved. The
standard should require that the iterators defined by the standard
collections go beyond the minimum iterator requirements in this way to
define unambiguously that the code above should work.

Proposed resolution:

Add the following text to section 23.1 [lib.container.requirements]:

The iterator and const_iterator types defined by a standard container may be
classes. If they are, any ==, !=, >, <, >=, or <= operator functions defined
for these classes to satisfy iterator requirements must be defined in the
std namespace, not as member functions.

(Perhaps someone on the library committee can word it better. This is the
best I could do.)

    -- Darin


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




