Skip to content

<algorithm>: search_n returns first when count<=0 #148

@andreyfe1

Description

@andreyfe1

Hi,
It was found that search_n returns first when count<=0.
However, the C++ standard says (N4659 draft, the last draft before C++17):

Returns: The first iterator i in the range [first, last-count) such that for every non-negative integer n less than count the following corresponding conditions hold: (i + n) == value, pred((i+ n),value) != false. Returns last if no such iterator is found.

It seems that if n>=0 and count <=0 we don't have a chance to apply a predicate. So, we won't find "such iterator". According to this logic last should be returned. Am I right?
I'm just curious why does search_n implementation return first?

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWG issue neededA wording defect that should be submitted to LWG as a new issueresolvedSuccessfully resolved without a commit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions