s, {}, &Particle::mass);
        print("Sort by mass using a projection", particles, '\n');
    }

Output:

    
    
    Sort using the default operator<
    0 1 2 3 4 5 6 7 8 9
    Sort using a standard library compare function object
    9 8 7 6 5 4 3 2 1 0
    Sort using a custom function object
    0 1 2 3 4 5 6 7 8 9
    Sort using a lambda expression
    9 8 7 6 5 4 3 2 1 0
     
    Sort by name using a projection
    Electron : 0.511
    Muon     : 105.66
    Neutron  : 939.57
    Positron : 0.511
    Proton   : 938.27
    Tau      : 1776.86
     
    Sort by mass using a projection
    Electron : 0.511
    Positron : 0.511
    Muon     : 105.66
    Proton   : 938.27
    Neutron  : 939.57
    Tau      : 1776.86

###  [ [ edit
](/mwiki/index.php?title=cpp/algorithm/ranges/sort&action=edit&section=7 "Edit
section: See also") ]  See also

[ ranges::partial_sort  ](/w/cpp/algorithm/ranges/partial_sort "cpp/algorithm/ranges/partial sort") (C++20)  |  sorts the first N elements of a range   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_partial_sort&action=edit)  
---|---  
[ ranges::stable_sort  ](/w/cpp/algorithm/ranges/stable_sort "cpp/algorithm/ranges/stable sort") (C++20)  |  sorts a range of elements while preserving order between equal elements   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_stable_sort&action=edit)  
[ ranges::partition  ](/w/cpp/algorithm/ranges/partition "cpp/algorithm/ranges/partition") (C++20)  |  divides a range of elements into two groups   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_partition&action=edit)  
[ sort  ](/w/cpp/algorithm/sort "cpp/algorithm/sort") |  sorts a range into ascending order   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/dsc_sort&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/algorithm/ranges/sort&oldid=150629
](https://en.cppreference.com/mwiki/index.php?title=cpp/algorithm/ranges/sort&oldid=150629)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A list of recent changes in the wiki \[r\]")
  * [ FAQ ](/w/Cppreference:FAQ)
  * [ Offline version ](/w/Cppreference:Archives)

#####  Toolbox

  * [ What links here ](/w/Special:WhatLinksHere/cpp/algorithm/ranges/sort "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/algorithm/ranges/sort "Recent changes in pages linked from this page \[k\]")
  * [ Upload file ](http://upload.cppreference.com/w/Special:Upload "Upload files \[u\]")
  * [ Special pages ](/w/Special:SpecialPages "A list of all special pages \[q\]")
  * [ Printable version ](/mwiki/index.php?title=cpp/algorithm/ranges/sort&printable=yes "Printable version of this page \[p\]")
  * [ Permanent link ](/mwiki/index.php?title=cpp/algorithm/ranges/sort&oldid=150629 "Permanent link to this revision of the page")
  * [ Page information ](/mwiki/index.php?title=cpp/algorithm/ranges/sort&action=info)

  * In other languages 

  * [ Deutsch ](http://de.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ Español ](http://es.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ Français ](http://fr.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ Italiano ](http://it.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ 日本語 ](http://ja.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ Português ](http://pt.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ Русский ](http://ru.cppreference.com/w/cpp/algorithm/ranges/sort "cpp/algorithm/ranges/sort")
  * [ 中文 ](http://zh.cppreference.com/w