title: Sorting vector of objects with respect to std::variant field
body: <p>I have a vector of <code>Row</code> objects, which I need to sort based on a field which is a <code>std::variant</code>.</p>
  <p>Below is the program</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;variant&gt;
  #include &lt;sstream&gt;
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  #include &lt;variant&gt;
  using namespace std;
  using Value = std::variant&lt;int,std::string&gt;;
  class Row{
      public:
      Row(Value data):data(data){}
      Row(const Row &amp;aCopy){
          this-&gt;data = aCopy.data;
      }
      Row&amp; operator=(const Row &amp;aCopy){
          this-&gt;data = aCopy.data;
          return *this;
      }
      ~Row(){}
      
      Value getData(){
          return this-&gt;data;
      }
      
      protected:
      Value data;
      
  };
  
  
  std::vector&lt;std::unique_ptr&lt;Row&gt;&gt;&amp; printUnique(std::vector&lt;std::unique_ptr&lt;Row&gt;&gt; &amp;theRow){
      return theRow;
  }
  
  
  
  int main()
  {
  
      std::vector&lt;Row&gt; theRow;
      Row a(1);
      Row b(-2);
      Row c(3);
      theRow.push_back(a);
      theRow.push_back(b);
      theRow.push_back(c);
      Value v = theRow.at(1).getData();
      sort(theRow.begin(),theRow.end(),[](const auto&amp; lhs, const auto&amp; rhs){
        Value v1 = lhs.getData();
        Value v2 = rhs.getData();
        return v1&lt;v2;
      });
      
      
      
      return 0;
  }
  </code></pre>
  <p>I am getting error in the sort function</p>
  <blockquote>
  <pre><code>main.cpp:65:13: error: passing ‘const Row’ as ‘this’ argument discards qualifiers [-fpermissive]
     65 |       Value v1 = lhs.getData();
        |             ^~
  </code></pre>
  </blockquote>
  <p>I am completely clueless here what to do. Any help here will be highly appreciated.</p>