From the way you presented your question, I assume that you say "iteration", but actually means "work with the algorithm."
The behavior does not apply to the container, but to the type of container iterator.
std::array::iterator_typesatisfies RandomAccessIterator , are the same as std::vectorand std::deque.
This means that given
std::array<int,6> myArray = {0,0,0,0,0,0};
and
auto end = myArray.begin()
you can add a number to it n...
auto end = myArray.begin() + 4;
... causes the iterator to move one element after the nth element in the array. Since this is the very definition for an iterator endfor a sequence,
std::find_if(myArray.begin(), myArray.begin() + 4, ... )
works just fine. A slightly more intuitive example:
#include <algorithm>
#include <array>
#include <iostream>
#define N 4
int main()
{
std::array<char, 6> myArray = { 'a', 'b', 'c', 'd', 'e', 'f' };
auto end = myArray.begin() + N;
if ( std::find( myArray.begin(), end, 'd' ) != end )
{
std::cout << "Found.\n";
}
return 0;
}
This finds the 4th element in the array and prints "Found."
#define N 4 #define N 3, .
, , n. , N <= myArray.size() myArray.end(), .
: