Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::adjacent_find

 

std::adjacent_find is an STL algorithm to search a container for two adjacent identical values.

 

 

 

 

 

Project and source code

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: Qt4 GUI Application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

 

main.cpp

 

#include <algorithm>
#include <cassert>
#include <vector>

int main()
{
  std::vector<int> v;
  v.push_back(0);
  v.push_back(1);
  v.push_back(2);
  v.push_back(2);
  v.push_back(3);
  v.push_back(4);

  assert(std::adjacent_find(v.begin(),v.end())!=v.end());
  assert(*std::adjacent_find(v.begin(),v.end())==2);

  //Remove duplicate
  v[2]=5;

  assert(std::adjacent_find(v.begin(),v.end())==v.end());
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict