1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2017-2017. |
4 | // Distributed under the Boost Software License, Version 1.0. |
5 | // (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | // |
8 | // See http://www.boost.org/libs/move for documentation. |
9 | // |
10 | ////////////////////////////////////////////////////////////////////////////// |
11 | |
12 | #ifndef BOOST_MOVE_ALGO_UNIQUE_HPP |
13 | #define BOOST_MOVE_ALGO_UNIQUE_HPP |
14 | |
15 | #include <boost/move/detail/config_begin.hpp> |
16 | #include <boost/move/utility_core.hpp> |
17 | |
18 | namespace boost { |
19 | namespace movelib { |
20 | |
21 | //! <b>Requires</b>: The comparison function shall be an equivalence relation. The type of *first shall satisfy |
22 | //! the MoveAssignable requirements |
23 | //! |
24 | //! <b>Effects</b>: For a nonempty range, eliminates all but the first element from every consecutive group |
25 | //! of equivalent elements referred to by the iterator i in the range [first + 1, last) for which the |
26 | //! following conditions hold: pred(*(i - 1), *i) != false. |
27 | //! |
28 | //! <b>Returns</b>: The end of the resulting range. |
29 | //! |
30 | //! <b>Complexity</b>: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate. |
31 | template<class ForwardIterator, class BinaryPredicate> |
32 | ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) |
33 | { |
34 | if (first != last) { |
35 | ForwardIterator next(first); |
36 | ++next; |
37 | for (; next != last; ++next, ++first) { |
38 | if (pred(*first, *next)) { //Find first equal element |
39 | while (++next != last) |
40 | if (!pred(*first, *next)) |
41 | *++first = ::boost::move(*next); |
42 | break; |
43 | } |
44 | } |
45 | ++first; |
46 | } |
47 | return first; |
48 | } |
49 | |
50 | } //namespace movelib { |
51 | } //namespace boost { |
52 | |
53 | #include <boost/move/detail/config_end.hpp> |
54 | |
55 | #endif //#define BOOST_MOVE_ALGO_UNIQUE_HPP |
56 | |