Date
2000-09-04.00:00:00
Message id
2042

Content

The note in paragraph 6 suggests that the invalidation rules for references, pointers, and iterators in paragraph 5 permit a reference- counted implementation (actually, according to paragraph 6, they permit a "reference counted implementation", but this is a minor editorial fix).

However, the last sub-bullet is so worded as to make a reference-counted implementation unviable. In the following example none of the conditions for iterator invalidation are satisfied:

    // first example: "*******************" should be printed twice
    string original = "some arbitrary text", copy = original;
    const string & alias = original;

    string::const_iterator i = alias.begin(), e = alias.end();
    for(string::iterator j = original.begin(); j != original.end(); ++j)
        *j = '*';
    while(i != e)
        cout << *i++;
    cout << endl;
    cout << original << endl;

Similarly, in the following example:

    // second example: "some arbitrary text" should be printed out
    string original = "some arbitrary text", copy = original;
    const string & alias = original;

    string::const_iterator i = alias.begin();
    original.begin();
    while(i != alias.end())
        cout << *i++;

I have tested this on three string implementations, two of which were reference counted. The reference-counted implementations gave "surprising behavior" because they invalidated iterators on the first call to non-const begin since construction. The current wording does not permit such invalidation because it does not take into account the first call since construction, only the first call since various member and non-member function calls.