title: non-standard conditional sort algorithm STL c++
body: <p>I am studying STL and have found <a href="http://web.stanford.edu/class/cs106l/course-reader/Ch7_STLAlgorithms.pdf" rel="nofollow">this</a> very interesting PDF from Stanford with tasks. One of the tasks is to sort a list of songs but in such a way that songs labelled as "My song" were always first in the list.</p>
  
  <p>So, if we have: </p>
  
  <pre><code>vector &lt;string&gt; song{ "Viva", "Pompeii", "My song", "We remain", "My song", "It is time" };
  </code></pre>
  
  <p>The output should be:</p>
  
  <pre><code>My song, My song ... (in ascending or descending order);
  </code></pre>
  
  <p>I have solved the problem by using  <code>iter_swap</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code> #include &lt;iostream&gt;
      #include &lt;string&gt;
      #include &lt;vector&gt;
      #include &lt;numeric&gt;
      #include &lt;algorithm&gt;
      using namespace std;
  
  
      void print(vector &lt;string&gt; song) {
          for (vector &lt;string&gt; ::iterator it = song.begin(), end = song.end(); it != end; ++it) {
              cout &lt;&lt; *it &lt;&lt; " ";
          }
      }
  
      int main() {
          vector &lt;string&gt; song{ "Viva", "Pompeii", "My song", "We remain", "My song", "It is time" };
          vector &lt;string&gt; ::iterator start = song.begin();
  
          for (vector &lt;string&gt; ::iterator begin = song.begin(), end = song.end(); begin != end; ++begin){
              if (*begin == "My song") {
                  iter_swap(start, begin);
                  ++start;
              }
          }
          sort(start, song.end());
          print(song);
          cin.get();
          }
  </code></pre>
  
  <p>But before that, I had been struggling for a while to solve the problem by using only <code>sort</code> algorithm. Unfortunately, I did not come up with the solution. Could you say if it is possible to write a sorting function <code>compare</code>which would solve the task? I am not sure if it is possible, since <code>sort</code> just does simple ordering. Am I right?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;numeric&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  bool compare(string x, string y) {
      // What to write here?
  }
  
  void print(vector &lt;string&gt; song) {
      for (vector &lt;string&gt; ::iterator it = song.begin(), end = song.end(); it != end; ++it) {
          cout &lt;&lt; *it &lt;&lt; " ";
      }
  }
  
  int main() {
      vector &lt;string&gt; song{ "Viva", "Pompeii", "My song", "We remain", "My song", "It is time" };
  
      sort(start, song.end(), compare);
      print(song);
      cin.get();
      }
  </code></pre>