Adobe Source Libraries 2.0.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
sort.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_ALGORITHM_SORT_HPP
9#define ADOBE_ALGORITHM_SORT_HPP
10
11#include <adobe/config.hpp>
12
13#include <boost/range/begin.hpp>
14#include <boost/range/end.hpp>
15
16#include <algorithm>
17#include <functional>
18
19/**************************************************************************************************/
20
21namespace adobe {
22
23/**************************************************************************************************/
33/**************************************************************************************************/
39template <class RandomAccessRange>
40inline void sort(RandomAccessRange& range) {
41 return std::sort(boost::begin(range), boost::end(range));
42}
43
49template <class RandomAccessIterator, class Compare>
50inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
51 return std::sort(first, last, std::bind(comp, std::placeholders::_1, std::placeholders::_2));
52}
53
59template <typename I, // I models RandomAccessIterator
60 typename C, // C models StrictWeakOrdering(T, T)
61 typename P>
62// P models UnaryFunction(value_type(I)) -> T
63inline void sort(I f, I l, C c, P p) {
64 return std::sort(
65 f, l,
66 std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2)));
67}
68
74template <typename R, // I models RandomAccessRange
75 typename C, // C models StrictWeakOrdering(T, T)
76 typename P>
77// P models UnaryFunction(value_type(I)) -> T
78inline void sort(R& r, C c, P p) {
79 return adobe::sort(
80 boost::begin(r), boost::end(r),
81 std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2)));
82}
83
89template <class RandomAccessRange, class Compare>
90inline void sort(RandomAccessRange& range, Compare comp) {
91 return adobe::sort(boost::begin(range), boost::end(range), comp);
92}
93
99template <class RandomAccessRange>
100inline void stable_sort(RandomAccessRange& range) {
101 return std::stable_sort(boost::begin(range), boost::end(range));
102}
103
109template <class RandomAccessIterator, class Compare>
110inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
111 return std::stable_sort(first, last,
112 std::bind(comp, std::placeholders::_1, std::placeholders::_2));
113}
114
120template <class RandomAccessRange, class Compare>
121inline void stable_sort(RandomAccessRange& range, Compare comp) {
122 return adobe::stable_sort(boost::begin(range), boost::end(range), comp);
123}
124
130template <class InputRange, class RandomAccessRange>
131inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range) {
132 return std::partial_sort_copy(boost::begin(range), boost::end(range),
133 boost::begin(result_range), boost::end(result_range));
134}
135
141template <class InputRange, class RandomAccessRange>
142inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range) {
143 return std::partial_sort_copy(boost::begin(range), boost::end(range),
144 boost::begin(result_range), boost::end(result_range));
145}
146
152template <class InputIterator, class RandomAccessIterator, class Compare>
153inline void partial_sort_copy(InputIterator first, InputIterator last,
154 RandomAccessIterator result_first, RandomAccessIterator result_last,
155 Compare comp) {
156 return std::partial_sort_copy(first, last, result_first, result_last,
157 std::bind(comp, std::placeholders::_1, std::placeholders::_2));
158}
159
165template <class InputRange, class RandomAccessRange, class Compare>
166inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range, Compare comp) {
167 return adobe::partial_sort_copy(boost::begin(range), boost::end(range),
168 boost::begin(result_range), boost::end(result_range), comp);
169}
170
176template <class InputRange, class RandomAccessRange, class Compare>
177inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range,
178 Compare comp) {
179 return adobe::partial_sort_copy(boost::begin(range), boost::end(range),
180 boost::begin(result_range), boost::end(result_range), comp);
181}
182
183/**************************************************************************************************/
184
185} // namespace adobe
186
187/**************************************************************************************************/
188
189#endif
190
191/**************************************************************************************************/
void sort(RandomAccessRange &range)
sort implementation
Definition sort.hpp:40
void stable_sort(RandomAccessRange &range)
sort implementation
Definition sort.hpp:100
void partial_sort_copy(InputRange &range, RandomAccessRange &result_range)
sort implementation
Definition sort.hpp:131