DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK

mismatch(3C++)

mismatch -- find the first location at which two arrays differ

Synopsis

```   template <class T>
const T* mismatch(
const T* b1, const T* e1,
const T* b2, const T* e2
);
template <class T>
const T* mismatch_r(
int (*rel)(const T*,const T*),
const T* b1, const T* e1,
const T* b2, const T* e2
);
```

Assumptions

(1) For the plain version, T::operator== defines an equivalence relation on T.

(2) For the relational version, rel defines an equivalence relation on T.

Description

These functions return a pointer to the leftmost element within the first array which is not equal to the corresponding element in the second array. Returns 0 if no mismatch occurs.

```   template <class T>
const T* mismatch(
const T* b1, const T* e1,
const T* b2, const T* e2
);
```

Uses T::operator== to define equality.

```   template <class T>
const T* mismatch_r(
int (*rel)(const T*,const T*),
const T* b1, const T* e1,
const T* b2, const T* e2
);
```

Uses rel to define equality.

Complexity

If N and M are the sizes of the arrays, the complexity is O(N+M). At most min(N,M) equality tests are done.

Notes

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(3C++), Block(3C++)