title: Create Set of Every Permutation and Sign Variation of Members of a Set (C++)
body: <p>Suppose I am given a vector of unknown size.  For example, it could be</p>
  
  <p><code>std::vector&lt;int&gt; myset1({1, 2, 3});</code></p>
  
  <p>Or it could be anything else.  That's just an example.  Now, suppose I want to write a function that returns a vector of vectors.  However, each vector in this vector must be distinct permutations of the original.  So in this case, I would expect the function to return a vector containing the sets {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, and {3, 2, 1} (pay no attention to the ordering).</p>
  
  <p>That might be straightforward with some kind of recursion.  But what if I also wanted to also account for the sign of each element?  So for example:</p>
  
  <p><code>std::vector&lt;int&gt; myset2({1, 2});</code></p>
  
  <p>I would expect the function to return {1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1} (I'm not concerned with the ordering).</p>
  
  <p>I'm struggling to think of a way to design this elegantly.  As you can imagine, with larger sets, it becomes a necessity to use such a function rather than to list out each set by hand, but no ideas are coming to my head at the moment.  How would you achieve this?</p>