Title
Incomplete specification of EqualityComparable for std::forward_list
Status
c++11
Section
[container.requirements]
Submitter
Daniel Krügler

Created on 2008-06-24.00:00:00 last changed 161 months ago

Messages

Date: 2011-04-28.21:34:33

Proposed resolution:

Option (C):

  1. In [container.requirements.general] change Table 90 -- Container requirements as indicated:

    1. Change the text in the Assertion/note column in the row for "X u;" as follows:

      post: u.size() == 0empty() == true

    2. Change the text in the Assertion/note column in the row for "X();" as follows:

      X().size() == 0empty() == true

    3. Change the text in the Operational Semantics column in the row for "a == b" as follows:

      == is an equivalence relation. a.size()distance(a.begin(), a.end()) == b.size()distance(b.begin(), b.end()) && equal(a.begin(), a.end(), b.begin())

    4. Add text in the Ass./Note/pre-/post-condition column in the row for "a == b" as follows:

      Requires: T is EqualityComparable

    5. Change the text in the Operational Semantics column in the row for "a.size()" as follows:

      a.end() - a.begin()distance(a.begin(), a.end())

    6. Change the text in the Operational Semantics column in the row for "a.max_size()" as follows:

      size()distance(begin(), end()) of the largest possible container

    7. Change the text in the Operational Semantics column in the row for "a.empty()" as follows:

      a.size() == 0a.begin() == a.end()

  2. In [container.requirements.general] change Table 93 — Allocator-aware container requirements as indicated:

    1. Change the text in the Assertion/note column in the row for "X() / X u;" as follows:

      Requires: A is DefaultConstructible post: u.size() == 0u.empty() == true, get_allocator() == A()

    2. Change the text in the Assertion/note column in the row for "X(m) / X u(m);" as follows:

      post: u.size() == 0u.empty() == true, get_allocator() == m

  3. In [sequence.reqmts] change Table 94 — Sequence container requirements as indicated:

    1. Change the text in the Assertion/note column in the row for "X(n, t) / X a(n, t)" as follows:

      post: size()distance(begin(), end()) == n [..]

    2. Change the text in the Assertion/note column in the row for "X(i, j) / X a(i, j)" as follows:

      [..] post: size() == distance between i and jdistance(begin(), end()) == distance(i, j) [..]

    3. Change the text in the Assertion/note column in the row for "a.clear()" as follows:

      a.erase(a.begin(), a.end()) post: size() == 0a.empty() == true

  4. In [associative.reqmts] change Table 96 — Associative container requirements as indicated:

    Not every occurrence of size() was replaced, because all current associative containers have a size. The following changes ensure consistency regarding the semantics of "erase" for all tables and adds some missing objects
    1. Change the text in the Complexity column in the row for X(i,j,c)/Xa(i,j,c); as follows:

      N log N in general (N == distance(i, j)is the distance from i to j); ...

    2. Change the text in the Complexity column in the row for "a.insert(i, j)" as follows:

      N log(a.size() + N) (N is the distance from i to j) where N == distance(i, j)

    3. Change the text in the Complexity column in the row for "a.erase(k)" as follows:

      log(a.size()) + a.count(k)

    4. Change the text in the Complexity column in the row for "a.erase(q1, q2)" as follows:

      log(a.size()) + N where N is the distance from q1 to q2 == distance(q1, q2).

    5. Change the text in the Assertion/note column in the row for "a.clear()" as follows:

      a.erase(a.begin(),a.end()) post: size() == 0a.empty() == true

    6. Change the text in the Complexity column in the row for "a.clear()" as follows:

      linear in a.size()

    7. Change the text in the Complexity column in the row for "a.count(k)" as follows:

      log(a.size()) + a.count(k)

  5. In [unord.req] change Table 98 — Unordered associative container requirements as indicated:

    The same rational as for Table 96 applies here
    1. Change the text in the Assertion/note column in the row for "a.clear()" as follows:

      [..] Post: a.size() == 0empty() == true

Date: 2010-10-21.18:28:33

[ 2010 Pittsburgh: ]

Moved to Ready for Pittsburgh.

Date: 2010-01-30.00:00:00

[ 2010-01-30 Howard updated Table numbers. ]

Date: 2010-10-21.18:28:33

[ 2009-10 Santa Cruz: ]

Reopened. N2986 was rejected in full committee on procedural grounds.

Date: 2010-10-21.18:28:33

[ 2009-10 Santa Cruz: ]

Mark NAD Editorial. Addressed by N2986.

Date: 2009-07-26.00:00:00

[ 2009-07-26 Daniel updated proposed resolution C. ]

Date: 2010-10-21.18:28:33

[ 2009-07 Frankfurt ]

Other operational semantics (see, for example, Tables 82 and 83) are written in terms of a container's size() member. Daniel to update proposed resolution C.

Howard: Commented out options A and B.
Date: 2010-10-21.18:28:33

[ post San Francisco: ]

Martin provided wording for Option C.

Date: 2010-10-21.18:28:33

[ San Francisco: ]

There's an Option C: change the requirements table to use distance().

LWG found Option C acceptable.

Martin will draft the wording for Option C.

Date: 2008-06-24.00:00:00

Table 89, Container requirements, defines operator== in terms of the container member function size() and the algorithm std::equal:

== is an equivalence relation. a.size() == b.size() && equal(a.begin(), a.end(), b.begin()

The new container forward_list does not provide a size member function by design but does provide operator== and operator!= without specifying it's semantic.

Other parts of the (sequence) container requirements do also depend on size(), e.g. empty() or clear(), but this issue explicitly attempts to solve the missing EqualityComparable specification, because of the special design choices of forward_list.

I propose to apply one of the following resolutions, which are described as:

  1. Provide a definition, which is optimal for this special container without previous size test. This choice prevents two O(N) calls of std::distance() with the corresponding container ranges and instead uses a special equals implementation which takes two container ranges instead of 1 1/2.
  2. The simple fix where the usual test is adapted such that size() is replaced by distance with corresponding performance disadvantages.

Both proposal choices are discussed, the preferred choice of the author is to apply (A).

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4101
2010-10-21 18:28:33adminsetmessages: + msg4100
2010-10-21 18:28:33adminsetmessages: + msg4099
2010-10-21 18:28:33adminsetmessages: + msg4098
2010-10-21 18:28:33adminsetmessages: + msg4097
2010-10-21 18:28:33adminsetmessages: + msg4096
2010-10-21 18:28:33adminsetmessages: + msg4095
2010-10-21 18:28:33adminsetmessages: + msg4094
2010-10-21 18:28:33adminsetmessages: + msg4093
2008-06-24 00:00:00admincreate