FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-sort/examples/readme_example.cpp at 2.x.y-develop · Morwenn/cpp-sort · GitHub
Morwenn
/
cpp-sort
Public
Notifications
You must be signed in to change notification settings
Fork
63
Star
721
Code
Issues
36
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-sort
/
examples
/
readme_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (31 loc) · 990 Bytes
Breadcrumbs
cpp-sort
/
examples
/
readme_example.cpp
Copy path
File metadata and controls
36 lines (31 loc) · 990 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Copyright (c) 2021 Morwenn
* SPDX-License-Identifier: MIT
*/
#
include
<
algorithm
>
#
include
<
cassert
>
#
include
<
forward_list
>
#
include
<
functional
>
#
include
<
vector
>
#
include
<
cpp-sort/adapters.h
>
#
include
<
cpp-sort/sorters.h
>
int
main
()
{
struct
wrapper
{
int
value; };
std::forward_list<wrapper> li = { {
5
}, {
8
}, {
3
}, {
2
}, {
9
} };
std::vector<wrapper> vec = { {
5
}, {
8
}, {
3
}, {
2
}, {
9
} };
//
When used, this sorter will use a pattern-defeating quicksort
//
to sort random-access collections, and a mergesort otherwise
cppsort::hybrid_adapter<
cppsort::pdq_sorter,
cppsort::merge_sorter
> sorter;
//
Sort li and vec in reverse order using their value member
sorter
(li, std::greater{}, &wrapper::value);
sorter
(vec, std::greater{}, &wrapper::value);
assert
(
std::equal
(
li.
begin
(), li.
end
(),
vec.
begin
(), vec.
end
(),
[](
const
auto
& lhs,
const
auto
& rhs) {
return
lhs.
value
== rhs.
value
; }
));
}
Back
|
FazBrowse Home
|
New Git URL