Skip to content

[SR-13937] Needless precondition in Collection distance #56334

@dabrahams

Description

@dabrahams
Previous ID SR-13937
Radar None
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 79626c31d137f57975f0b894a587bfcd

Issue Description:

The precondition in Collection.distance that reads “Only BidirectionalCollections can have end come before start” fires even for {{BidirectionalCollection}} models unless the implementor of the collection is hyper-vigilant and implements their own distance method.

We could solve this problem by adding a default implementation of distance for BidirectionalCollections, but we're already doing a test/branch even on collections that are non-bidirectional, to detect the precondition violation. We might as well just do the right thing in all cases.

#34981 takes a first crack at an implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions