Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:52

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2017-2017.
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // (See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // See http://www.boost.org/libs/move for documentation.
0009 //
0010 //////////////////////////////////////////////////////////////////////////////
0011 
0012 #ifndef BOOST_MOVE_ALGO_UNIQUE_HPP
0013 #define BOOST_MOVE_ALGO_UNIQUE_HPP
0014 
0015 #include <boost/move/detail/config_begin.hpp>
0016 #include <boost/move/utility_core.hpp>
0017 
0018 namespace boost {
0019 namespace movelib {
0020 
0021 //! <b>Requires</b>: The comparison function shall be an equivalence relation. The type of *first shall satisfy
0022 //! the MoveAssignable requirements
0023 //!
0024 //! <b>Effects</b>: For a nonempty range, eliminates all but the first element from every consecutive group
0025 //!   of equivalent elements referred to by the iterator i in the range [first + 1, last) for which the
0026 //!   following conditions hold: pred(*(i - 1), *i) != false.
0027 //!
0028 //! <b>Returns</b>: The end of the resulting range.
0029 //!
0030 //! <b>Complexity</b>: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate.
0031 template<class ForwardIterator, class BinaryPredicate>
0032 ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred)
0033 {
0034     if (first != last) {
0035       ForwardIterator next(first);
0036       ++next;
0037       for (; next != last; ++next, ++first) {
0038          if (pred(*first, *next)) { //Find first equal element
0039             while (++next != last)
0040                if (!pred(*first, *next))
0041                   *++first = ::boost::move(*next);
0042             break;
0043          }
0044       }
0045       ++first;
0046    }
0047    return first;
0048 }
0049 
0050 }  //namespace movelib {
0051 }  //namespace boost {
0052 
0053 #include <boost/move/detail/config_end.hpp>
0054 
0055 #endif   //#define BOOST_MOVE_ALGO_UNIQUE_HPP