Programming-Idioms

History of Idiom 28 > diff from v23 to v24

Edit summary for version 24 :
New Cpp implementation by user [GhassanPL]

Version 23

2016-02-16, 17:07:55

Version 24

2016-02-16, 18:34:47

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Imports
#include <algorithm>
Code
std::sort(begin(items), end(items), [](const auto& a, const auto& b) { return a.p < b.p; });
Comments bubble
This sort is not a stable sort.
Doc URL
http://en.cppreference.com/w/cpp/algorithm/sort