Bubble sort implementation in C++ I was wondering if this implementation of bubble sort could be improved. Are there any things that I have done wrong?

template&lt;typename Element&gt;
void bubble_sort(Element arr[], size_t size) {
    auto sorted_elements = 1u;
    bool sorted = false;
    while (!sorted) {
        sorted = true;
        for (auto index = 0u; index &lt; size - sorted_elements; ++index) {
            if (arr[index] &gt; arr[index + 1]) {
                auto temp = arr[index + 1];
                arr[index + 1] = arr[index];
                arr[index] = temp;
                sorted = false;
            }
        }
        ++sorted_elements;
    }
}
Implementation

size - sorted_elements might not return what you expect if size == 0 (it returns std::numeric_limits&lt;unsigned int&gt;::max()). This makes the intended check fail for size == 0. This can be fixed by changing the while loops condition to sorted_elements &lt; size &amp;&amp; !sorted.
You could use std::swap(arr[index], arr[index + 1]); to swap the elements. This way, the preferred assignment operation (copy or move) for Element will be used (if Element provides its own specialization). Currently, you always copy, which might not always be preferred (e.g. with large std::strings).