Topic: Naming for find_end and search


Author: musiphil@bawi.org (Seungbeom Kim)
Date: Tue, 2 Jan 2007 18:21:17 GMT
Raw View
I find that find_end() and search() are specified strikingly similarly,
even though their names don't suggest so:

------------------------------------------------------------------------
25.1.3 Find End [lib.alg.find.end]

template<class ForwardIterator1, class ForwardIterator2>
  ForwardIterator1
    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
             ForwardIterator2 first2, ForwardIterator2 last2);

template<class ForwardIterator1, class ForwardIterator2,
         class BinaryPredicate>
  ForwardIterator1
    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
             ForwardIterator2 first2, ForwardIterator2 last2,
             BinaryPredicate pred);

1 Effects: Finds a subsequence of equal values in a sequence.
2 Returns: The last iterator i in the range [first1, last1 -
(last2-first2)) such that for any non-negative integer n <
(last2-first2), the following corresponding conditions hold: *(i+n) ==
*(first2+n), pred(*(i+n),*(first2+n)) != false. Returns last1 if no such
iterator is found.
3 Complexity: At most (last2 - first2) * (last1 - first1 - (last2 -
first2) + 1) applications of the corresponding predicate.
------------------------------------------------------------------------
25.1.9 Search [lib.alg.search]

template<class ForwardIterator1, class ForwardIterator2>
  ForwardIterator1
    search(ForwardIterator1 first1, ForwardIterator1 last1,
           ForwardIterator2 first2, ForwardIterator2 last2);

template<class ForwardIterator1, class ForwardIterator2,
         class BinaryPredicate>
  ForwardIterator1
    search(ForwardIterator1 first1, ForwardIterator1 last1,
           ForwardIterator2 first2, ForwardIterator2 last2,
           BinaryPredicate pred);

1 Effects: Finds a subsequence of equal values in a sequence.
2 Returns: The first iterator i in the range [first1, last1 - (last2 -
first2)) such that for any non-negative integer n less than last2 -
first2 the following corresponding conditions hold: *(i + n) == *(first2
+ n), pred(*(i + n), *(first2 + n)) != false. Returns last1 if no such
iterator is found.
3 Complexity: At most (last1 - first1) * (last2 - first2) applications
of the corresponding predicate.
------------------------------------------------------------------------

Their effects are exactly the same, and the only significant difference
seems to be "the last iterator" vs. "the first iterator", with some
additional editorial differences.

Then I wonder why they have been named so, without reflecting their
similarity. For example, search() (and search_n()) could have been named
find_first() (and find_first_n()). Of course, find_end() could also have
been named find_last() to match the naming scheme of find_last_of() in
basic_string. In many other cases in the standard library, 'end' matches
with 'begin', and 'last' with 'first'.

Is there any consideration going on to solve this inconsistency?
Otherwise, I think we can adopt find_first() as a synonym for search(),
find_first_n() for search_n(), and find_last() for find_end(), so that
people can use more consistent names if they wish to. What do you think?

--
Seungbeom Kim

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]