OK, here is yet another question of the “How to do it better in STL?” series.
We have two ranges, designated by first1, last1, and first2. We want to find the number of different i’s from [0, last1-first1] such that *(first1 + i) == *(first2 + i)
For example:
{a, b, c, d, d, b, c, a}
{a, a, b, c, d, c, c, a}
^ ^ ^ ^
For these two ranges the answer is 4.
Is there a good STL way to do it? I mean preferrably without any manual for’s, while’s etc. Thanks!
UPDATE
Konrad has pointed out in the comments below that this relies on slightly nefarious implicit conversion from
booltoint. Whilst this is completely legal, it can be avoided thus: