Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page 590: The description of "search" from <algorithm> is inconsistent with the example and incorrectly worded. #126

Closed
WraithGlade opened this issue Jan 20, 2020 · 1 comment

Comments

@WraithGlade
Copy link

In this text from the page:

The algorithm locates sequence 2 within sequence 1. In other words, it returns the first iterator i in sequence 1 such that for each non-negative integer n, *(=i + n) equals (ipt_begin2 + n), or if you provide a predicate pred((i + n), *(ipt_begin2 + n)) is true. The search algorithm returns ipt_begin1 if sequence 2 is empty or ipt_begin2 if no subsequence is found. This is different from find because it locates a subsequence rather than a single element.

ForwardIterator search([ ep], fwd_begin1, fwd_end1, fwd_begin2, fwd_end2, [pred]);

There are two main problems here:

(1) Notice that the variables "ipt_begin1" and "ipt_begin2" are different from what's actually used in the function declaration given later, which instead uses "fwd_" variants of the names.

(2) Most importantly, the phrase "or ipt_begin2 if no subsequence is found" appears to be wrong and misleading. The test case code shows that it appears to actually return an end iterator (which is far more reasonable), not a begin iterator. This was very confusing when I first read it. I'm sure it will confuse others too.

In contrast though, returning a begin iterator for searching for an empty subseq makes sense, since an empty subsequence is a subsequence of any sequence, but that's a different case.

Consider a general rewrite of the paragraph in general too, perhaps.

@JLospinoso
Copy link
Owner

Thanks, @WraithGlade!

kruschk pushed a commit to kruschk/ccc that referenced this issue Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants