Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

lexicographical_compare()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that returns true if one sequence compares lexicographically less than another, false otherwise

Synopsis

#include <algorithm>

namespace std {
  template <class InputIterator1, class InputIterator2>
  bool
  lexicographical_compare(InputIterator1 start1,
                          InputIterator1 finish1,
                          InputIterator2 start2,
                          InputIterator2 finish2);

  template <class InputIterator1, class InputIterator2, 
            class Compare>
   bool
   lexicographical_compare(InputIterator1 start1,
                           InputIterator1 finish1,
                           InputIterator2 start2,
                           InputIterator2 finish2, 
                           Compare comp);
}

Description

The lexicographical_compare() functions compare each element in the range [start1, finish1) to the corresponding element in the range [start2, finish2) 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 data types included in the standard library.

Complexity

lexicographical_compare() performs at most min((finish1 - start1), (finish2 - start2)) applications of the comparison function.

Example

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.3.8



Previous fileTop of DocumentContentsIndex pageNext file