title: Sorting named numeric vectors in Rcpp
body: <p>In a function, I want to calculate numeric values, give names to them and return a sorted <code>NumericVector</code> in Rcpp. I can sort the vectors (using <a href="https://gallery.rcpp.org/articles/sorting/" rel="noreferrer">this</a>), but the order of the names of the values remains the same. </p>
  
  <pre><code>library(Rcpp)
  x &lt;- c(a = 1, b = 5, c = 3)
  cppFunction('
  NumericVector foo(NumericVector x) {
    std::sort(x.begin(), x.end());
    return(x);
  }')
  foo(x)
  ## a b c 
  ## 1 3 5 
  </code></pre>
  
  <p>I want the function to return this:</p>
  
  <pre><code>## a c b 
  ## 1 3 5 
  </code></pre>
  
  <p>Is it possible? How can I achieve this? </p>