An r-length permuter in c++ In relation to the question I asked here, I myself came up with an answer. I would like constructive criticism and tips to improve it to make it efficient like the other answers that have been posted.

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

int main() {
    std::vector&lt;int&gt; job_list;
    std::set&lt;std::vector&lt;int&gt;&gt; permutations;
    for (unsigned long i = 0; i &lt; 7; i++) {
        int job;
        std::cin &gt;&gt; job;
        job_list.push_back(job);
    }
    std::sort(job_list.begin(), job_list.end());
    std::vector&lt;int&gt; original_permutation = job_list;
    do {
        std::next_permutation(job_list.begin(), job_list.end());
        permutations.insert(std::vector&lt;int&gt;(job_list.begin(), job_list.begin() + 3));
    } while (job_list != original_permutation);

    for (auto&amp; permutation : permutations) {
        for (auto&amp; pair : permutation) {
            std::cout &lt;&lt; pair &lt;&lt; " ";
        }
        std::endl(std::cout);
    }

    return 0;
}
In general, the code is nice and readable.  Here's some small suggestions:


This:

for (unsigned long i = 0; i &lt; 7; i++) {
    int job;
    std::cin &gt;&gt; job;
    job_list.push_back(job);
}


can be simplified (?) to

std::copy_n(std::istream_iterator&lt;int&gt;{std::cin}, 7, std::back_inserter(job));

Introduce variables when you use them.  For example, the declaration of permutations may be moved after reading and sorting the numbers.
Marking original_permutation as const indicates that it is used for comparison only.
Use emplace:

permutations.emplace(job_list.begin(), job_list.begin() + 3);


instead of

permutations.insert(std::vector&lt;int&gt;(job_list.begin(), job_list.begin() + 3));

const auto&amp; in the for loops.  Also, std::cout &lt;&lt; '\n' instead of std::endl(std::cout).
Consider extracting the functionality into a function and changing magic numbers to arguments.


Of course, there are more efficient ways to do this.  Your code generates
$$ 7! = 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1 = 5040 $$
permutations, but only end up with
$$ 7^{\underline{3}} = 7 \times 6 \times 5 = 210 $$
results, and let std::set discard the remaining \$5040 - 210 = 4830\$ permutations.  You can modify your code so that it only stores one in \$4! = 24\$ permutations, but the other answers to the linked question provide better algorithms.