Std :: array iterator range without template?

With C arrays, it's pretty easy to write code that accepts arrays of any size:

void func( T* itBegin, T* itEnd );

void main() {
    T arr1[1];
    func( std::begin(arr1), std::end(arr1) );
    T arr2[2];
    func( std::begin(arr2), std::end(arr2) );
}

How can I do this with std :: arrays?

void func( ??? itBegin, ??? itEnd );

void main() {
    std::array<T,1> arr1;
    func( std::begin(arr1), std::end(arr1) );
    std::array<T,2> arr2;
    func( std::begin(arr2), std::end(arr2) );
}

The problem is that in MSVC 2010 std::array<T,N>::iteratoris different for different N. Is this a bug in MSVC 2010? If not, what is the reason for this design? Yes, I could get pointers from std :: array and pass them instead of iterators, but isn't that too ugly?

BTW are the boost::array<T,N>::iteratorsame for everyone N.

+3
source share
3 answers
template <class I>
void func(I begin, I end)
{
    for (auto x = begin; x != end; ++x)
        something_with(*x);
}

Define them as a type parameter, and then just use them as if they were pointers. Everything that behaves like pointer-like will compile, and what will not, will not.

, , operator=, operator* operator++.

, begin/end, array<N>, , array<N>::iterator - array<M>::iterator.

+4

, , std::array ; std::array<int, 1> std::array<int, 2>, (, , - ).

, C :

func( &arr1[0], &arr1[0] + arr1.size() );

, , .

+2
template <class I>
void func(I begin, I end);
0