forked from stlab/adobe_source_libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.hpp
More file actions
197 lines (159 loc) · 5.79 KB
/
sort.hpp
File metadata and controls
197 lines (159 loc) · 5.79 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
Copyright 2013 Adobe
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
/**************************************************************************************************/
#ifndef ADOBE_ALGORITHM_SORT_HPP
#define ADOBE_ALGORITHM_SORT_HPP
#include <adobe/config.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <algorithm>
#include <functional>
/**************************************************************************************************/
namespace adobe {
/**************************************************************************************************/
/*!
\defgroup sort sort
\ingroup sorting
\see
- [STL documentation for sort](https://www.boost.org/sgi/stl/sort.html)
- [STL documentation for stable_sort](https://www.boost.org/sgi/stl/stable_sort.html)
- [STL documentation for partial_sort_copy](https://www.boost.org/sgi/stl/partial_sort_copy.html)
*/
/**************************************************************************************************/
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessRange>
inline void sort(RandomAccessRange& range) {
return std::sort(boost::begin(range), boost::end(range));
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessIterator, class Compare>
inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
return std::sort(first, last, [&comp](const auto& a, const auto& b) {
return std::invoke(comp, a, b);
});
}
/*!
\ingroup sort
\brief sort implementation
*/
template <typename I, // I models RandomAccessIterator
typename C, // C models StrictWeakOrdering(T, T)
typename P>
// P models UnaryFunction(value_type(I)) -> T
inline void sort(I f, I l, C c, P p) {
return std::sort(
f, l,
[&p, &c](const auto& a, const auto& b) {
return std::invoke(c, std::invoke(p, a), std::invoke(p, b));
});
}
/*!
\ingroup sort
\brief sort implementation
*/
template <typename R, // I models RandomAccessRange
typename C, // C models StrictWeakOrdering(T, T)
typename P>
// P models UnaryFunction(value_type(I)) -> T
inline void sort(R& r, C c, P p) {
return adobe::sort(boost::begin(r), boost::end(r), c, p);
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessRange, class Compare>
inline void sort(RandomAccessRange& range, Compare comp) {
return adobe::sort(boost::begin(range), boost::end(range), comp);
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessRange>
inline void stable_sort(RandomAccessRange& range) {
return std::stable_sort(boost::begin(range), boost::end(range));
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessIterator, class Compare>
inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
return std::stable_sort(first, last,
[&comp](const auto& a, const auto& b) {
return std::invoke(comp, a, b);
});
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class RandomAccessRange, class Compare>
inline void stable_sort(RandomAccessRange& range, Compare comp) {
return adobe::stable_sort(boost::begin(range), boost::end(range), comp);
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class InputRange, class RandomAccessRange>
inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range) {
return std::partial_sort_copy(boost::begin(range), boost::end(range),
boost::begin(result_range), boost::end(result_range));
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class InputRange, class RandomAccessRange>
inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range) {
return std::partial_sort_copy(boost::begin(range), boost::end(range),
boost::begin(result_range), boost::end(result_range));
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class InputIterator, class RandomAccessIterator, class Compare>
inline void partial_sort_copy(InputIterator first, InputIterator last,
RandomAccessIterator result_first, RandomAccessIterator result_last,
Compare comp) {
return std::partial_sort_copy(first, last, result_first, result_last,
[&comp](const auto& a, const auto& b) {
return std::invoke(comp, a, b);
});
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class InputRange, class RandomAccessRange, class Compare>
inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range, Compare comp) {
return adobe::partial_sort_copy(boost::begin(range), boost::end(range),
boost::begin(result_range), boost::end(result_range), comp);
}
/*!
\ingroup sort
\brief sort implementation
*/
template <class InputRange, class RandomAccessRange, class Compare>
inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range,
Compare comp) {
return adobe::partial_sort_copy(boost::begin(range), boost::end(range),
boost::begin(result_range), boost::end(result_range), comp);
}
/**************************************************************************************************/
} // namespace adobe
/**************************************************************************************************/
#endif
/**************************************************************************************************/