1 //////////////////////////////////////////////////////////////////////////////
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)
8 // See http://www.boost.org/libs/move for documentation.
10 //////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_MOVE_ALGO_UNIQUE_HPP
13 #define BOOST_MOVE_ALGO_UNIQUE_HPP
15 #include <boost/move/detail/config_begin.hpp>
16 #include <boost/move/utility_core.hpp>
21 //! <b>Requires</b>: The comparison function shall be an equivalence relation. The type of *first shall satisfy
22 //! the MoveAssignable requirements
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.
28 //! <b>Returns</b>: The end of the resulting range.
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)
35 ForwardIterator next(first);
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);
50 } //namespace movelib {
53 #include <boost/move/detail/config_end.hpp>
55 #endif //#define BOOST_MOVE_ALGO_UNIQUE_HPP