Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

lexicographical_compare()

Module:  Standard C++ Library   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

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.