So, to see how std :: end works, we can see How does std :: end know the end of an array? and see the signature for std::end :
template< class T, std::size_t N > T* end( T (&array)[N] );
and it uses a non-type template parameter to infer the size of the array, and it's just a matter of pointer arithmetic to get the end:
return array + N ;
For std::begin signature is identical except for the name:
template< class T, std::size_t N > T* begin( T (&array)[N] );
and calculating the beginning of an array is just a matter of array to evade the pointer , which gives us a pointer to the first element of the array.
In C ++ 14, both of them become constexpr.
source share