# Selection sort implementation in C++

I was wondering if this implementation of selection sort could be improved. Are there any things that I have done wrong?

template<typename Element>
void selection_sort(Element arr[], size_t size) {
auto index_toSort = 0u;
while (index_toSort < size) {
auto index_smallest = index_toSort;
for (auto index = index_toSort; index < size; ++index) {
if (arr[index] < arr[index_smallest]) {
index_smallest = index;
}
}
std::swap(arr[index_toSort], arr[index_smallest]);
++index_toSort;
}
}

• Seems fine to me as-is (though I'd probably rename index_toSort to index_to_sort for consistency/personal aesthetics). Of course, one could always generalize for different ordering and/or iterators, but those aspects seem out of scope for your sort implementations (at least to me). – hoffmale Nov 14 '17 at 12:48
• @hoffmale, I disagree. The asker is the new generation of C++ programmers. We should try to teach them modern (or at least C++) ways first. Otherwise, there is no real reason to learn or use C++, as their code will be easily ported to other languages. They're getting worst of all worlds when using C way. Idioms are there for a reason. C way is very prideful way, because then programmers will need to reimplement everything to fit their ecosystem. That doesn't end well if they are not team of experts in the domain of their problem. Using them in general is not bad, but bad if better tool exists. – Incomputable Nov 14 '17 at 19:09

template<typename I>