Blame view

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