title: C++. How to sort by module with saving the original order of elements
body: <p>I'm trying to sort element in vector by module with the condition that the initial order of equal (by module) elements does not change. Logic tells me that the comparator should take less than or equal to save the original order.</p>
  <pre><code>std::sort(v.begin(), v.end(), [](int a, int b) {
      return abs(a) &lt;= abs(b);
  });
  </code></pre>
  <p>But with and example of <code>1 -1 1 -1</code> my compiler return <code>-1 1 -1 1</code>. Unfortunately it saves order with less than sign(I don't understand why).</p>
  <p>Decided that <code>std::sort</code> is <strong>not stalbe</strong>, I tried to use <code>std::stable_sort</code> and with and example of <code>-1 1 1 -1 -1</code> it reversed elements in order <code>-1 -1 1 1 -1</code> - Although I expected that the order would not change with a sign less than or equal.</p>
  <p>What am I wrong about? Is there a lambda that is guaranteed to preserve the order of the elements?</p>