Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

lexicographical_compare


Algorithm

Summary

Compares two ranges lexicographically.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class InputIterator1, class InputIterator2>
 bool
 lexicographical_compare(InputIterator1 first,
                         InputIterator2 last1,
                         InputIterator2 first2,
                         InputIterator last2);

template <class InputIterator1, class InputIterator2, 
          class Compare>
 bool
 lexicographical_compare(InputIterator1 first,
                         InputIterator2 last1,
                         InputIterator2 first2,
                         InputIterator last2, Compare comp);

Description

The lexicographical_compare functions compare each element in the range [first1, last1) to the corresponding element in the range [first2, last2) using iterators i and j.

The first version of the algorithm uses operator< as the default comparison operator. It immediately returns true if it encounters any pair in which *i is less than *j, and immediately returns false if *j is less than *i. If the algorithm reaches the end of the first sequence before reaching the end of the second sequence, it also returns true.

The second version of the function takes an argument comp that defines a comparison function that is used in place of the default operator<.

The lexicographical_compare functions can be used with all the datatypes included in the standard library.

Complexity

lexicographical_compare performs at most min((last1 - first1), (last2 - first2)) applications of the comparison function.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998