The following code compiles fine on my system:
#include <array>
#include <type_traits>
static_assert(std::is_same<std::array<int, 5>::iterator,
std::array<int, 7>::iterator>::value, ":(");
Is that behavior guaranteed by the standard? Is the iterator type independent of the array size?
If it is guaranteed, is there any way to abstract from the element type and ignore the size?
template<typename T, size_t n>
void foobar(std::array<T, n>::iterator it)
That is, is there any way to write the above array-specific code without mentioning the size n?
Note that I do not want to resort to T*, even though in release mode the iterator probably is a T*.
No, it’s not guaranteed. Each array type
array<T, size_t>has a nested member typedef namediteratorwhose type is implementation defined.