c++ general int array and vector iterator -
in following code, need define iterator can iterate on both vector<int>
, int[100]
. how define mi
here?
template<class arraytype> void array_show(arraytype array, size_t arraysize) { // how define mi???? (mi = array; array != m.end(); array++) std::cout << " " << *mi << std::endl; }
here example below. importantpart use arraytype&
- reference, way regular array not decayed pointer - way possible read size inside array_show.
template<class arraytype> void array_show(arraytype& array, size_t arraysize) { // how define mi???? (auto mi = std::begin(array); mi != std::end(array); mi++) std::cout << " " << *mi << std::endl; }