Insertion sort C++14 implementation I have implemented insertion sort using C++. Is there any way to improve my code and is it CppCoreGuideline compliant? As I passed the vector as const in print method, do I need to specify const in range for loop?

/*
 *  Insertion Sort
 */

#include &lt;iostream&gt;
#include &lt;vector&gt;

void insertionSort(std::vector&lt;int&gt; &amp;v);
void print(const std::vector&lt;int&gt; &amp;v);

int main()
{
    std::ios_base::sync_with_stdio(false);

    std::vector&lt;int&gt; v {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    // Print the vector before sorting.
    print(v);
    // Sort
    insertionSort(v);
    // Print the vector after sorting.
    print(v);

    return 0;
}

void insertionSort(std::vector&lt;int&gt; &amp;v) {
    for (auto i = v.begin() + 1; i != v.end(); ++i) {
        int key = *i;

        auto j = i - 1;
        while (j &gt;= v.begin() &amp;&amp; *j &gt; key) {
            *(j+1) = *j;
            --j;
        }
        *(j+1) = key;
    }
    return;
}

void print(const std::vector&lt;int&gt; &amp;v) {
    for (const auto &amp;i : v) {
        std::cout &lt;&lt; i &lt;&lt; " ";
    }
    std::cout &lt;&lt; "\n";
}
Advice 1

In your insertionSort you can remove the last statement (return). 

Advice 2

Making your insertion sort generic is easy:

template&lt;typename RandIt&gt;
void insertion_sort(RandIt begin, RandIt end)
{
    for (auto i = begin + 1; i != end; ++i)
    {
        auto key = *i;
        auto j = i - 1;

        while (j &gt;= begin and *j &gt; key)
        {
            *(j + 1) = *j;
            --j;
        }

        *(j + 1) = key;
    }
}

template&lt;typename Container&gt;
void insertion_sort(Container&amp; cont)
{
    insertion_sort(std::begin(cont), std::end(cont));
}


Advice 3

Making your print function generic is not hard either:

template&lt;typename RandIt&gt;
void print(RandIt begin, RandIt end)
{
    using value_type = typename std::iterator_traits&lt;RandIt&gt;::value_type;
    std::copy(begin, end, std::ostream_iterator&lt;value_type&gt;(std::cout, ", "));
    std::cout &lt;&lt; std::endl;
}

template&lt;typename Container&gt;
void print(const Container&amp; container)
{
    print(std::begin(container), std::end(container));
}


Hope that helps.