Indeed you can obtain a pointer from the reference and use pointer arithmetic on it but if you have gone to all that trouble why not just use a good old for-loop, and stop one before the last element of the array, which sticking with pointers could look like so:
#include <iostream>
int main()
{
int obj[] = {1,2,3,4,5, 6,6, 7,8,9, 6,6,6, 0};
int something{6};
auto obj_size = sizeof obj / sizeof(int);
auto obj_begin = obj;
auto obj_one_before_end = obj_begin + obj_size - 1;
for ( auto pElement = obj_begin; pElement!=obj_one_before_end; ++pElement )
{
auto pnextElement = pElement + 1;
if ( *pElement == something && *pnextElement == something )
{
std::cout << "Doing something!!\n";
}
}
}
I have made the above a bit more verbose than it needs to be to try to be as clear as possible.
Or using array index values:
int main()
{
int obj[] = {1,2,3,4,5, 6,6, 7,8,9, 6,6,6, 0};
int something{6};
auto obj_size = sizeof obj / sizeof(int);
auto range_length = obj_size - 1u;
for ( auto idx = 0u; idx != range_length; ++idx )
{
if ( obj[idx] == something && obj[idx+1] == something )
{
std::cout << "Doing something!!\n";
}
}
}
As you can see in both these forms the end of the loop case causes no problems as we have stopped one before the last item in the array.
Hope this provides you with food for thought if nothing else.