Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
unique.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_UNIQUE_HPP
9#define ADOBE_ALGORITHM_UNIQUE_HPP
10
11#include <adobe/config.hpp>
12
13#include <algorithm>
14#include <functional>
15#include <iterator>
16
18
19/**************************************************************************************************/
20
21namespace adobe {
22
23/**************************************************************************************************/
32/**************************************************************************************************/
38template <class ForwardRange>
39inline auto unique(ForwardRange& range) {
40 return std::unique(std::begin(range), std::end(range));
41}
42
48template <class ForwardIterator, class BinaryPredicate>
49inline ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) {
50 return std::unique(first, last, std::bind(pred, std::placeholders::_1, std::placeholders::_2));
51}
52
58template <class ForwardRange, class BinaryPredicate>
59inline auto unique(ForwardRange& range,
60 BinaryPredicate pred) {
61 return adobe::unique(std::begin(range), std::end(range), pred);
62}
63
69template <class InputRange, class OutputIterator>
70inline OutputIterator unique_copy(InputRange& range, OutputIterator result) {
71 return std::unique_copy(std::begin(range), std::end(range), result);
72}
73
79template <class InputRange, class OutputIterator>
80inline OutputIterator unique_copy(const InputRange& range, OutputIterator result) {
81 return std::unique_copy(std::begin(range), std::end(range), result);
82}
83
89template <class InputIterator, class OutputIterator, class BinaryPredicate>
90inline OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result,
91 BinaryPredicate pred) {
92 return std::unique_copy(first, last, result,
93 std::bind(pred, std::placeholders::_1, std::placeholders::_2));
94}
95
101template <class InputRange, class OutputIterator, class BinaryPredicate>
102inline OutputIterator unique_copy(InputRange& range, OutputIterator result, BinaryPredicate pred) {
103 return adobe::unique_copy(std::begin(range), std::end(range), result, pred);
104}
105
111template <class InputRange, class OutputIterator, class BinaryPredicate>
112inline OutputIterator unique_copy(const InputRange& range, OutputIterator result,
113 BinaryPredicate pred) {
114 return adobe::unique_copy(std::begin(range), std::end(range), result, pred);
115}
116
118template <class T>
119inline void sort_unique(T& c) {
120 sort(c);
121 c.erase(unique(c), std::end(c));
122}
123
124/**************************************************************************************************/
125
126} // namespace adobe
127
128/**************************************************************************************************/
129
130#endif
131
132/**************************************************************************************************/
void sort(RandomAccessRange &range)
sort implementation
Definition sort.hpp:40
auto unique(ForwardRange &range)
unique implementation
Definition unique.hpp:39
OutputIterator unique_copy(InputRange &range, OutputIterator result)
unique implementation
Definition unique.hpp:70
void sort_unique(T &c)
Sorts the sequence container c and erases all but one matching element.
Definition unique.hpp:119