Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) std::mismatch

 

std::mismatch is an STL algorithm to find a mismatch between two containers.

 

#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(3);

  std::vector<int> w(v);

  assert(v==w);

  assert(std::mismatch(v.begin(),v.end(),w.begin())
    == std::make_pair(v.end(),w.end()));

  w[1] = 42;

  assert(std::mismatch(v.begin(),v.end(),w.begin())
    == std::make_pair(v.begin()+1,w.begin()+1));

}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict