adjacent_find man page on Solaris

Man page or keyword search:  
man Server   20652 pages
apropos Keyword Search (all sections)
Output format
Solaris logo
[printable version]

adjacent_find(3C++)		       -		   adjacent_find(3C++)

Standard C++ Library Copyright 1998, Rogue Wave Software, Inc.

NAME
       adjacent_find

	-  Find	 the  first  adjacent  pair of elements in a sequence that are
       equivalent.

SYNOPSIS
       #include <algorithm>
       template <class ForwardIterator>
 ForwardIterator
 adjacent_find(ForwardIterator first,
	       ForwardIterator last);

template <;class ForwardIterator, class BinaryPredicate>
ForwardIterator
 adjacent_find(ForwardIterator first, ForwardIterator last,
	       BinaryPredicate pred);

DESCRIPTION
       There are two versions of the adjacent_find algorithm. The first	 finds
       equal  adjacent elements in the sequence defined by iterators first and
       last and returns an iterator i pointing to the first of the equal  ele‐
       ments.  The second version lets you specify your own binary function to
       test for a condition. It returns an iterator i pointing to the first of
       the  pair  of elements that meet the conditions of the binary function.
       In other words, adjacent_find returns the first iterator	 i  such  that
       both  i	and  i + 1 are in the range [first, last) for which one of the
       following conditions holds:

       *i == *(i + 1)

       or

       pred(*i,*(i + 1)) == true

       If adjacent_find does not find a match, it returns last.

COMPLEXITY
       adjacent_find performs exactly find(first,last,value) - first  applica‐
       tions of the corresponding predicate.

EXAMPLE
//
// find.cpp
//
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
 {
  typedef vector<int>::iterator iterator;
  int d1[10] = {0,1,2,2,3,4,2,2,6,7};

   // Set up a vector
  vector<int> v1(d1,d1 + 10);

   // Try find
  iterator it1 = find(v1.begin(),v1.end(),3);

   // Try find_if
  iterator it2 =
   find_if(v1.begin(),v1.end(),bind1st(equal_to<int>(),3));

   // Try both adjacent_find variants
  iterator it3 = adjacent_find(v1.begin(),v1.end());

  iterator it4 =
     adjacent_find(v1.begin(),v1.end(),equal_to<int>());

   // Output results
  cout << *it1 << " " << *it2 << " " << *it3 << " "
	<< *it4 << endl;

  return 0;
 }

Program Output :

3 3 2 2

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.

SEE ALSO
       find

Rogue Wave Software		  02 Apr 1998		   adjacent_find(3C++)
[top]

List of man pages available for Solaris

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net