With C arrays, it is fairly easy to write code that takes 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 that 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>::iterator is different for different N. Is this a bug in MSVC 2010? If not, what is the rationale of this design? Yes, I could get pointers from the std::array and pass them instead of iterators, but isn't that unnecessarily ugly?
BTW, boost::array<T,N>::iterator are the same for all N.
void func( T* itBegin, T* itEnd )is already a templated function, so I cannot se how can you comply with that "without template" requirement.T. Seemain, which also usesTand cannot be templated.